Exemplo n.º 1
0
  private void _displayRespStrInFrame() {

    final JFrame frame = new JFrame("Google Static Map - Error");
    GUIUtils.setAppIcon(frame, "69.png");
    // frame.setDefaultCloseOperation(DISPOSE_ON_CLOSE);

    JTextArea response = new JTextArea(_respStr, 25, 80);
    response.addMouseListener(
        new MouseListener() {
          public void mouseClicked(MouseEvent e) {}

          public void mousePressed(MouseEvent e) {
            /*frame.dispose();*/
          }

          public void mouseReleased(MouseEvent e) {}

          public void mouseEntered(MouseEvent e) {}

          public void mouseExited(MouseEvent e) {}
        });

    frame.setContentPane(new JScrollPane(response));
    frame.pack();

    GUIUtils.centerOnScreen(frame);
    frame.setVisible(true);
  }
Exemplo n.º 2
0
 public MovieClass() {
   super();
   setLayout(new BorderLayout());
   int cnt = 0;
   for (MovieFeedMessage message : movieFeed.getMessages()) {
     if (cnt > 0 && cnt < 10) data += message + "\n";
     cnt++;
   }
   setBorder(new TitledBorder(new EtchedBorder(), "Top 10 Movies"));
   t = new JTextArea(data);
   t.setEditable(false);
   add(t);
   t.addMouseListener(
       new MouseAdapter() {
         public void mouseClicked(MouseEvent e) {
           if (Desktop.isDesktopSupported()) {
             try {
               Desktop.getDesktop().browse(new URL("http://www.fandango.com/boxoffice").toURI());
             } catch (IOException | URISyntaxException e1) {
               // TODO Auto-generated catch block
               e1.printStackTrace();
             }
           }
         }
       });
 }
  public void addGui(final DownloadDialog gui) {
    buildDownloadAreaInputFields();
    final JPanel dlg = new JPanel(new GridBagLayout());

    tfOsmUrl.getDocument().addDocumentListener(new OsmUrlRefresher());

    // select content on receiving focus. this seems to be the default in the
    // windows look+feel but not for others. needs invokeLater to avoid strange
    // side effects that will cancel out the newly made selection otherwise.
    tfOsmUrl.addFocusListener(new SelectAllOnFocusHandler(tfOsmUrl));
    tfOsmUrl.setLineWrap(true);
    tfOsmUrl.setBorder(latlon[0].getBorder());

    dlg.add(new JLabel(tr("min lat")), GBC.std().insets(10, 20, 5, 0));
    dlg.add(latlon[0], GBC.std().insets(0, 20, 0, 0));
    dlg.add(new JLabel(tr("min lon")), GBC.std().insets(10, 20, 5, 0));
    dlg.add(latlon[1], GBC.eol().insets(0, 20, 0, 0));
    dlg.add(new JLabel(tr("max lat")), GBC.std().insets(10, 0, 5, 0));
    dlg.add(latlon[2], GBC.std());
    dlg.add(new JLabel(tr("max lon")), GBC.std().insets(10, 0, 5, 0));
    dlg.add(latlon[3], GBC.eol());

    dlg.add(
        new JLabel(
            tr("URL from www.openstreetmap.org (you can paste an URL here to download the area)")),
        GBC.eol().insets(10, 20, 5, 0));
    dlg.add(tfOsmUrl, GBC.eop().insets(10, 0, 5, 0).fill());
    tfOsmUrl.addMouseListener(
        new MouseAdapter() {
          @Override
          public void mousePressed(MouseEvent e) {
            checkPopup(e);
          }

          @Override
          public void mouseClicked(MouseEvent e) {
            checkPopup(e);
          }

          @Override
          public void mouseReleased(MouseEvent e) {
            checkPopup(e);
          }

          private void checkPopup(MouseEvent e) {
            if (e.isPopupTrigger()) {
              OsmUrlPopup popup = new OsmUrlPopup();
              popup.show(tfOsmUrl, e.getX(), e.getY());
            }
          }
        });
    dlg.add(showUrl, GBC.eop().insets(10, 0, 5, 5));
    showUrl.setEditable(false);
    showUrl.setBackground(dlg.getBackground());
    showUrl.addFocusListener(new SelectAllOnFocusHandler(showUrl));

    gui.addDownloadAreaSelector(dlg, tr("Bounding Box"));
    this.parent = gui;
  }
 public void install(JTextArea textArea) {
   textArea.addCaretListener(this);
   textArea.addComponentListener(this);
   textArea.addFocusListener(this);
   textArea.addKeyListener(this);
   textArea.addMouseListener(this);
   textArea.addMouseMotionListener(this);
 }
Exemplo n.º 5
0
  public DistributedTextEditor() {
    area1.setFont(new Font("Monospaced", Font.PLAIN, 12));

    area2.setFont(new Font("Monospaced", Font.PLAIN, 12));
    ((AbstractDocument) area1.getDocument()).setDocumentFilter(dec);
    area2.setEditable(false);

    Container content = getContentPane();
    content.setLayout(new BoxLayout(content, BoxLayout.Y_AXIS));

    JScrollPane scroll1 =
        new JScrollPane(
            area1, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
    content.add(scroll1, BorderLayout.CENTER);

    JScrollPane scroll2 =
        new JScrollPane(
            area2, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
    content.add(scroll2, BorderLayout.CENTER);

    content.add(ipaddress, BorderLayout.CENTER);
    content.add(portNumber, BorderLayout.CENTER);

    JMenuBar JMB = new JMenuBar();
    setJMenuBar(JMB);
    JMenu file = new JMenu("File");
    JMenu edit = new JMenu("Edit");
    JMB.add(file);
    JMB.add(edit);

    file.add(Listen);
    file.add(Connect);
    file.add(Disconnect);
    file.addSeparator();
    file.add(Save);
    file.add(SaveAs);
    file.add(Quit);

    edit.add(Copy);
    edit.add(Paste);
    edit.getItem(0).setText("Copy");
    edit.getItem(1).setText("Paste");

    Save.setEnabled(false);
    SaveAs.setEnabled(false);
    Disconnect.setEnabled(false);

    setDefaultCloseOperation(EXIT_ON_CLOSE);
    pack();
    area1.addKeyListener(k1);
    area1.addMouseListener(m1);
    setTitle("Disconnected");
    setVisible(true);
    area1.insert("Welcome to Hjortehandlerne's distributed text editor. \n", 0);

    this.addWindowListener(w1);
  }
Exemplo n.º 6
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;
  }
Exemplo n.º 7
0
  private void initUI() {

    setLayout(new BorderLayout());
    dump = new JTextArea();
    dump.setEditable(false);
    dump.setFont(font);
    dump.addMouseListener(new ObjectWorkerTool.TextIdGrapper(node, con));

    JScrollPane scroller = new JScrollPane(dump);
    add(scroller, BorderLayout.CENTER);
  }
Exemplo n.º 8
0
  public void createPopupMenu() {
    JMenuItem menuItem;

    // Create the popup menu.
    JPopupMenu popup = new JPopupMenu();
    menuItem = new JMenuItem("A popup menu item");
    menuItem.addActionListener(this);
    popup.add(menuItem);
    menuItem = new JMenuItem("Another popup menu item");
    menuItem.addActionListener(this);
    popup.add(menuItem);

    // Add listener to the text area so the popup menu can come up.
    MouseListener popupListener = new PopupListener(popup);
    output.addMouseListener(popupListener);
  }
Exemplo n.º 9
0
  /** Creates a new instance of HistoryViewer */
  public RawDataViewer(FloatDataSet floatData) {
    // initialize content
    content = new JTextArea();
    content.setEditable(false);
    content.setMargin(new Insets(10, 10, 10, 10));
    content.setBackground(Color.white);
    content.setForeground(Color.DARK_GRAY);
    content.setFont(new Font("Arial", Font.BOLD, 12));

    // initialize popupMenu
    menu = new JPopupMenu();
    JMenuItem saveItem = new JMenuItem("Save to File"); // , GUIFactory.getIcon("save16.gif"));
    saveItem.setActionCommand("save");
    saveItem.addActionListener(new Listener());
    menu.add(saveItem);

    chooser = new JFileChooser();
    boolean denySaveSecurity = false;
    try {
      chooser.setFileFilter(
          new FileFilter() {
            public boolean accept(File f) {
              return f.isDirectory() || f.getName().endsWith(".txt");
            }

            public String getDescription() {
              return "TXT file";
            }
          });
      chooser.setSelectedFile(new File("rawDataSummary.txt"));
    } catch (AccessControlException ace) {
      denySaveSecurity = true;
    }

    addContent(floatData);

    content.addMouseListener(new Listener());
  }
Exemplo n.º 10
0
  /**
   * Set up field such that double click inserts the current date If isDataPicker is True, a button
   * with a data picker is returned
   *
   * @param editor
   * @param isDatePicker
   * @return
   */
  public static Optional<JComponent> getDateTimeExtraComponent(
      FieldEditor editor, Boolean isDatePicker, Boolean isoFormat) {
    ((JTextArea) editor)
        .addMouseListener(
            new MouseAdapter() {

              @Override
              public void mouseClicked(MouseEvent e) {
                if (e.getClickCount() == 2) { // double click
                  String date = EasyDateFormat.isoDateFormat().getCurrentDate();
                  editor.setText(date);
                }
              }
            });

    // insert a datepicker, if the extras field contains this command
    if (isDatePicker) {
      DatePickerButton datePicker = new DatePickerButton(editor, isoFormat);
      return Optional.of(datePicker.getDatePicker());
    } else {
      return Optional.empty();
    }
  }
Exemplo n.º 11
0
  private void addAdhocPacketPanel() {
    // Create UI elements for sending ad-hoc messages.
    final JTextArea adhocMessages = new JTextArea();
    adhocMessages.setEditable(true);
    adhocMessages.setForeground(new Color(1, 94, 35));
    tabbedPane.add("Ad-hoc message", new JScrollPane(adhocMessages));
    tabbedPane.setToolTipTextAt(3, "Panel that allows you to send adhoc packets");

    // Add pop-up menu.
    JPopupMenu menu = new JPopupMenu();
    JMenuItem menuItem = new JMenuItem("Message");
    menuItem.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            adhocMessages.setText(
                "<message to=\"\" id=\""
                    + StringUtils.randomString(5)
                    + "-X\"><body></body></message>");
          }
        });
    menu.add(menuItem);

    menuItem = new JMenuItem("IQ Get");
    menuItem.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            adhocMessages.setText(
                "<iq type=\"get\" to=\"\" id=\""
                    + StringUtils.randomString(5)
                    + "-X\"><query xmlns=\"\"></query></iq>");
          }
        });
    menu.add(menuItem);

    menuItem = new JMenuItem("IQ Set");
    menuItem.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            adhocMessages.setText(
                "<iq type=\"set\" to=\"\" id=\""
                    + StringUtils.randomString(5)
                    + "-X\"><query xmlns=\"\"></query></iq>");
          }
        });
    menu.add(menuItem);

    menuItem = new JMenuItem("Presence");
    menuItem.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            adhocMessages.setText(
                "<presence to=\"\" id=\"" + StringUtils.randomString(5) + "-X\"/>");
          }
        });
    menu.add(menuItem);
    menu.addSeparator();

    menuItem = new JMenuItem("Send");
    menuItem.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            if (!"".equals(adhocMessages.getText())) {
              AdHocPacket packetToSend = new AdHocPacket(adhocMessages.getText());
              connection.sendPacket(packetToSend);
            }
          }
        });
    menu.add(menuItem);

    menuItem = new JMenuItem("Clear");
    menuItem.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            adhocMessages.setText(null);
          }
        });
    menu.add(menuItem);

    // Add listener to the text area so the popup menu can come up.
    adhocMessages.addMouseListener(new PopupListener(menu));
  }
Exemplo n.º 12
0
  private void addBasicPanels() {
    JSplitPane allPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT);
    allPane.setOneTouchExpandable(true);

    messagesTable =
        new DefaultTableModel(
            new Object[] {"Hide", "Timestamp", "", "", "Message", "Id", "Type", "To", "From"}, 0) {
          private static final long serialVersionUID = 8136121224474217264L;

          public boolean isCellEditable(int rowIndex, int mColIndex) {
            return false;
          }

          public Class<?> getColumnClass(int columnIndex) {
            if (columnIndex == 2 || columnIndex == 3) {
              return Icon.class;
            }
            return super.getColumnClass(columnIndex);
          }
        };
    JTable table = new JTable(messagesTable);
    // Allow only single a selection
    table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    // Hide the first column
    table.getColumnModel().getColumn(0).setMaxWidth(0);
    table.getColumnModel().getColumn(0).setMinWidth(0);
    table.getTableHeader().getColumnModel().getColumn(0).setMaxWidth(0);
    table.getTableHeader().getColumnModel().getColumn(0).setMinWidth(0);
    // Set the column "timestamp" size
    table.getColumnModel().getColumn(1).setMaxWidth(300);
    table.getColumnModel().getColumn(1).setPreferredWidth(90);
    // Set the column "direction" icon size
    table.getColumnModel().getColumn(2).setMaxWidth(50);
    table.getColumnModel().getColumn(2).setPreferredWidth(30);
    // Set the column "packet type" icon size
    table.getColumnModel().getColumn(3).setMaxWidth(50);
    table.getColumnModel().getColumn(3).setPreferredWidth(30);
    // Set the column "Id" size
    table.getColumnModel().getColumn(5).setMaxWidth(100);
    table.getColumnModel().getColumn(5).setPreferredWidth(55);
    // Set the column "type" size
    table.getColumnModel().getColumn(6).setMaxWidth(200);
    table.getColumnModel().getColumn(6).setPreferredWidth(50);
    // Set the column "to" size
    table.getColumnModel().getColumn(7).setMaxWidth(300);
    table.getColumnModel().getColumn(7).setPreferredWidth(90);
    // Set the column "from" size
    table.getColumnModel().getColumn(8).setMaxWidth(300);
    table.getColumnModel().getColumn(8).setPreferredWidth(90);
    // Create a table listener that listen for row selection events
    SelectionListener selectionListener = new SelectionListener(table);
    table.getSelectionModel().addListSelectionListener(selectionListener);
    table.getColumnModel().getSelectionModel().addListSelectionListener(selectionListener);
    allPane.setTopComponent(new JScrollPane(table));
    messageTextArea = new JTextArea();
    messageTextArea.setEditable(false);
    // Add pop-up menu.
    JPopupMenu menu = new JPopupMenu();
    JMenuItem menuItem1 = new JMenuItem("Copy");
    menuItem1.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            // Get the clipboard
            Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
            // Set the sent text as the new content of the clipboard
            clipboard.setContents(new StringSelection(messageTextArea.getText()), null);
          }
        });
    menu.add(menuItem1);
    // Add listener to the text area so the popup menu can come up.
    messageTextArea.addMouseListener(new PopupListener(menu));
    JPanel sublayout = new JPanel(new BorderLayout());
    sublayout.add(new JScrollPane(messageTextArea), BorderLayout.CENTER);

    JButton clearb = new JButton("Clear All Packets");

    clearb.addActionListener(
        new AbstractAction() {
          private static final long serialVersionUID = -8576045822764763613L;

          @Override
          public void actionPerformed(ActionEvent e) {
            messagesTable.setRowCount(0);
          }
        });

    sublayout.add(clearb, BorderLayout.NORTH);
    allPane.setBottomComponent(sublayout);

    allPane.setDividerLocation(150);

    tabbedPane.add("All Packets", allPane);
    tabbedPane.setToolTipTextAt(0, "Sent and received packets processed by Smack");

    // Create UI elements for client generated XML traffic.
    final JTextArea sentText = new JTextArea();
    sentText.setWrapStyleWord(true);
    sentText.setLineWrap(true);
    sentText.setEditable(false);
    sentText.setForeground(new Color(112, 3, 3));
    tabbedPane.add("Raw Sent Packets", new JScrollPane(sentText));
    tabbedPane.setToolTipTextAt(1, "Raw text of the sent packets");

    // Add pop-up menu.
    menu = new JPopupMenu();
    menuItem1 = new JMenuItem("Copy");
    menuItem1.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            // Get the clipboard
            Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
            // Set the sent text as the new content of the clipboard
            clipboard.setContents(new StringSelection(sentText.getText()), null);
          }
        });

    JMenuItem menuItem2 = new JMenuItem("Clear");
    menuItem2.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            sentText.setText("");
          }
        });

    // Add listener to the text area so the popup menu can come up.
    sentText.addMouseListener(new PopupListener(menu));
    menu.add(menuItem1);
    menu.add(menuItem2);

    // Create UI elements for server generated XML traffic.
    final JTextArea receivedText = new JTextArea();
    receivedText.setWrapStyleWord(true);
    receivedText.setLineWrap(true);
    receivedText.setEditable(false);
    receivedText.setForeground(new Color(6, 76, 133));
    tabbedPane.add("Raw Received Packets", new JScrollPane(receivedText));
    tabbedPane.setToolTipTextAt(2, "Raw text of the received packets before Smack process them");

    // Add pop-up menu.
    menu = new JPopupMenu();
    menuItem1 = new JMenuItem("Copy");
    menuItem1.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            // Get the clipboard
            Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
            // Set the sent text as the new content of the clipboard
            clipboard.setContents(new StringSelection(receivedText.getText()), null);
          }
        });

    menuItem2 = new JMenuItem("Clear");
    menuItem2.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            receivedText.setText("");
          }
        });

    // Add listener to the text area so the popup menu can come up.
    receivedText.addMouseListener(new PopupListener(menu));
    menu.add(menuItem1);
    menu.add(menuItem2);

    // Create a special Reader that wraps the main Reader and logs data to the GUI.
    ObservableReader debugReader = new ObservableReader(reader);
    readerListener =
        new ReaderListener() {
          public void read(final String str) {
            SwingUtilities.invokeLater(
                new Runnable() {
                  public void run() {
                    if (EnhancedDebuggerWindow.PERSISTED_DEBUGGER
                        && !EnhancedDebuggerWindow.getInstance().isVisible()) {
                      // Do not add content if the parent is not visible
                      return;
                    }

                    int index = str.lastIndexOf(">");
                    if (index != -1) {
                      if (receivedText.getLineCount() >= EnhancedDebuggerWindow.MAX_TABLE_ROWS) {
                        try {
                          receivedText.replaceRange("", 0, receivedText.getLineEndOffset(0));
                        } catch (BadLocationException e) {
                          e.printStackTrace();
                        }
                      }
                      receivedText.append(str.substring(0, index + 1));
                      receivedText.append(NEWLINE);
                      if (str.length() > index) {
                        receivedText.append(str.substring(index + 1));
                      }
                    } else {
                      receivedText.append(str);
                    }
                  }
                });
          }
        };
    debugReader.addReaderListener(readerListener);

    // Create a special Writer that wraps the main Writer and logs data to the GUI.
    ObservableWriter debugWriter = new ObservableWriter(writer);
    writerListener =
        new WriterListener() {
          public void write(final String str) {
            SwingUtilities.invokeLater(
                new Runnable() {
                  public void run() {
                    if (EnhancedDebuggerWindow.PERSISTED_DEBUGGER
                        && !EnhancedDebuggerWindow.getInstance().isVisible()) {
                      // Do not add content if the parent is not visible
                      return;
                    }

                    if (sentText.getLineCount() >= EnhancedDebuggerWindow.MAX_TABLE_ROWS) {
                      try {
                        sentText.replaceRange("", 0, sentText.getLineEndOffset(0));
                      } catch (BadLocationException e) {
                        e.printStackTrace();
                      }
                    }

                    sentText.append(str);
                    if (str.endsWith(">")) {
                      sentText.append(NEWLINE);
                    }
                  }
                });
          }
        };
    debugWriter.addWriterListener(writerListener);

    // Assign the reader/writer objects to use the debug versions. The packet reader
    // and writer will use the debug versions when they are created.
    reader = debugReader;
    writer = debugWriter;
  }
Exemplo n.º 13
0
  public void viewNotebook() {
    // TODO Auto-generated method stub
    // Log in to genspace

    System.out.println("Logging in");
    GenSpaceServerFactory.userLogin("jon", "test123");
    System.out.println("Getting my notes");
    JFrame frame = new JFrame("My Notebook");
    frame.setSize(800, 600);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    JPanel mainContainer = new JPanel();
    frame.add(mainContainer);
    mainContainer.setLayout(new BorderLayout(0, 9));
    List<Tool> toolStrings = GenSpaceServerFactory.getUsageOps().getAllTools();
    List<AnalysisEvent> events = GenSpaceServerFactory.getPrivUsageFacade().getMyNotes(null, null);
    final NoteListModel nlm = new NoteListModel();
    nlm.setMyList(events);
    final JTable noteList = new JTable();
    noteList.setModel(nlm);
    String[] toolNames = new String[toolStrings.size()];
    String blank = "";
    blank = toolNames[0];
    for (int i = 1; i < toolStrings.size(); i++) {
      toolNames[i] = toolStrings.get(i).getName();
    }
    System.out.println(Arrays.toString(toolNames));
    JComboBox dropdown = new JComboBox(toolNames); // dropdown box
    dropdown.addActionListener(
        new ActionListener() {

          @Override
          public void actionPerformed(ActionEvent e) {

            ItemSelectable is = (ItemSelectable) e.getSource();
            setFirstParam(selectedString(is));
            List<AnalysisEvent> searchEvents =
                GenSpaceServerFactory.getPrivUsageFacade().getMyNotes(firstParam, secondParam);
            nlm.setMyList(searchEvents);
            noteList.setModel(nlm);
            noteList.revalidate();
          }
        });
    JPanel sortBy = new JPanel(new FlowLayout());
    String[] sortByStrings = {" ", "Sort by tool", "Sort by date"};
    final JComboBox sortByDropdown = new JComboBox(sortByStrings);
    sortByDropdown.addActionListener(
        new ActionListener() {

          @Override
          public void actionPerformed(ActionEvent e) {
            if (sortByDropdown.getSelectedIndex() == 1) {
              setSecondParam("tool");
              List<AnalysisEvent> searchEvents =
                  GenSpaceServerFactory.getPrivUsageFacade().getMyNotes(firstParam, secondParam);
              nlm.setMyList(searchEvents);
              noteList.setModel(nlm);
              noteList.revalidate();
            }
            if (sortByDropdown.getSelectedIndex() == 2) {
              setSecondParam("date");
              List<AnalysisEvent> searchEvents =
                  GenSpaceServerFactory.getPrivUsageFacade().getMyNotes(firstParam, secondParam);
              nlm.setMyList(searchEvents);
              noteList.setModel(nlm);
              noteList.revalidate();
            }
          }
        });
    sortBy.add(sortByDropdown);
    JPanel searchPanel = new JPanel(new BorderLayout());
    final JTextArea searchBox =
        new JTextArea("Enter your search query here or use the dropdown below");
    searchBox.setEditable(true);
    searchBox.addMouseListener(
        new MouseAdapter() {
          @Override
          public void mousePressed(MouseEvent e) {
            if (searchBox
                .getText()
                .equals("Enter your search query here or use the dropdown below"))
              searchBox.setText("");
            super.mousePressed(e);
          }
        });
    JButton searchButton = new JButton("Search");
    searchButton.addMouseListener(
        new MouseAdapter() {
          public void mousePressed(MouseEvent event) {
            ItemSelectable searchName = (ItemSelectable) event.getSource();
            String query = searchBox.getText();
            setFirstParam(query);
            List<AnalysisEvent> searchQueryList =
                GenSpaceServerFactory.getPrivUsageFacade()
                    .getMyNotes(firstParam, secondParam); // same problem as above
            nlm.setMyList(searchQueryList);
            noteList.setModel(nlm);
            noteList.revalidate();
          }
        });
    JLabel searchLabel = new JLabel("Filter your notes here:");
    Font f = new Font("Dialog", Font.PLAIN, 24);
    searchLabel.setFont(f);
    searchPanel.add(searchLabel, BorderLayout.NORTH);
    searchPanel.add(searchBox, BorderLayout.CENTER);
    searchPanel.add(searchButton, BorderLayout.EAST);
    searchPanel.setBackground(Color.white);
    SimpleDateFormat format = new SimpleDateFormat("F/M/yy h:mm a");
    noteList.setSize(800, 600);
    noteList.getColumnModel().getColumn(0).setCellRenderer(MyCellRenderer);
    noteList.getColumnModel().getColumn(0).setCellEditor(new MyCellEditor());
    int lines = countLines(((MyCellEditor) MyCellEditor).getNoteText()); // counts lines needed
    System.out.println(lines);
    ((MyCellRenderer) MyCellRenderer).setLines(lines);
    noteList.setTableHeader(null);
    JScrollPane notePane = new JScrollPane(noteList);
    JPanel noteArea = new JPanel(new BorderLayout());
    JPanel sortArea = new JPanel(new BorderLayout()); // dropdown menus
    sortArea.add(searchPanel, BorderLayout.NORTH); // panel to hold sorting area
    sortArea.add(dropdown, BorderLayout.CENTER);
    sortArea.add(sortBy, BorderLayout.EAST);
    JLabel noteLabel = new JLabel("My Notebook:");
    noteLabel.setFont(f);
    noteArea.add(noteLabel, BorderLayout.NORTH);
    noteArea.add(notePane, BorderLayout.CENTER);
    mainContainer.add(noteArea, BorderLayout.CENTER);
    mainContainer.add(sortArea, BorderLayout.NORTH);
    mainContainer.setBackground(Color.white);
    frame.pack();
    frame.setVisible(true);
  }
Exemplo n.º 14
0
  /** Create the ViewKeys frame. */
  public ViewKeys(JFrame homeFrame, String keypairDescription) {

    final JDialog viewGeneratedKeysFrame = new JDialog(homeFrame, "Generated RSA Key Pair", true);

    KeypairPOJO keypair = null;
    final KeypairPOJO finalKeypair;

    JPanel parentPanel = new JPanel(new BorderLayout());
    JPanel textAreaPanel = new JPanel(new BorderLayout());
    JPanel buttonsPanel = new JPanel();
    buttonsPanel.setLayout(new GridLayout(1, 3, 10, 0));

    JTextArea keyPairtextArea = new JTextArea(20, 70);
    keyPairtextArea.setEditable(false);
    // keyPairtextArea.setEnabled(false);
    keyPairtextArea.setLineWrap(true);

    ArrayList<KeypairPOJO> registeredKeypairs = null;
    try {
      registeredKeypairs = KeypairDAO.getKeypairs();
    } catch (Exception e) {
      e.printStackTrace();
    }

    if (keypairDescription == null) {
      if (registeredKeypairs.isEmpty()) {
        JOptionPane.showMessageDialog(
            null, "There are no keypairs registered.", "Notice", JOptionPane.INFORMATION_MESSAGE);
      } else {
        keypair = registeredKeypairs.get(registeredKeypairs.size() - 1);
        keyPairtextArea.setText(
            "-----BEGIN RSA PUBLIC KEY-----\n"
                + "Public Exponent: "
                + keypair.getPublicExponent()
                + "\n"
                + "Modulus: "
                + keypair.getModulus()
                + "\n"
                + "-----END RSA PUBLIC KEY-----\n"
                + "-----BEGIN RSA PRIVATE KEY-----\n"
                + "Private Exponent: "
                + keypair.getPrivateExponent()
                + "\n"
                + "Modulus: "
                + keypair.getModulus()
                + "\n"
                + "-----END RSA PRIVATE KEY-----");
      }
    } else {
      try {
        keypair = KeypairDAO.getKeypairByDescription(keypairDescription);

        keyPairtextArea.setText(
            "-----BEGIN RSA PUBLIC KEY-----\n"
                + "Public Exponent: "
                + keypair.getPublicExponent()
                + "\n"
                + "Modulus: "
                + keypair.getModulus()
                + "\n"
                + "-----END RSA PUBLIC KEY-----\n"
                + "-----BEGIN RSA PRIVATE KEY-----\n"
                + "Private Exponent: "
                + keypair.getPrivateExponent()
                + "\n"
                + "Modulus: "
                + keypair.getModulus()
                + "\n"
                + "-----END RSA PRIVATE KEY-----");
      } catch (Exception e) {
        e.printStackTrace();
      }
    }

    finalKeypair = keypair;
    keyPairtextArea.addMouseListener(new PopUpMenuClickListener(keyPairtextArea));
    textAreaPanel.add(keyPairtextArea);

    JButton exportKeyPairToFileButton = new JButton("Export to file");
    exportKeyPairToFileButton.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent evt) {
            ExportKey.exportToFileAsPlainText(finalKeypair, viewGeneratedKeysFrame);
          }
        });

    JButton purgeKeyPairButton = new JButton("Purge key pair");
    purgeKeyPairButton.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent evt) {
            try {
              KeypairDAO.deleteKeypair(finalKeypair);
              viewGeneratedKeysFrame.dispose();
            } catch (Exception e) {
              e.printStackTrace();
            }
          }
        });

    JButton cancelButton = new JButton("Cancel");
    cancelButton.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent evt) {
            viewGeneratedKeysFrame.dispose();
          }
        });

    buttonsPanel.add(exportKeyPairToFileButton);
    buttonsPanel.add(purgeKeyPairButton);
    buttonsPanel.add(cancelButton);

    // parentPanel.add(headerPanel, BorderLayout.NORTH);
    parentPanel.add(textAreaPanel, BorderLayout.CENTER);
    parentPanel.add(buttonsPanel, BorderLayout.SOUTH);
    viewGeneratedKeysFrame.setContentPane(parentPanel);
    viewGeneratedKeysFrame.pack();
    viewGeneratedKeysFrame.validate();
    viewGeneratedKeysFrame.setResizable(true);
    viewGeneratedKeysFrame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
    viewGeneratedKeysFrame.setLocationRelativeTo(null);
    viewGeneratedKeysFrame.setVisible(true);
  }
Exemplo n.º 15
0
  /*
   * GUI Code to add a modpack to the selection
   */
  public static void addPack(ModPack pack) {
    if (!modPacksAdded) {
      modPacksAdded = true;
      packs.removeAll();
    }

    final int packIndex = packPanels.size();
    Logger.logInfo("Adding pack " + getModNum());
    final JPanel p = new JPanel();
    p.setBounds(0, (packIndex * 55), 420, 55);
    p.setLayout(null);
    JLabel logo = new JLabel(new ImageIcon(pack.getLogo()));
    logo.setBounds(6, 6, 42, 42);
    logo.setVisible(true);
    String info = "";
    if (pack.getInfo().length() > 60) {
      info = pack.getInfo().substring(0, 59) + "...";
    } else {
      info = pack.getInfo();
    }
    JTextArea filler = new JTextArea(pack.getName() + " : " + pack.getAuthor() + "\n" + info);
    filler.setBorder(null);
    filler.setEditable(false);
    filler.setForeground(Color.white);
    filler.setBounds(58, 6, 378, 42);
    filler.setBackground(new Color(255, 255, 255, 0));
    MouseListener lin =
        new MouseListener() {
          @Override
          public void mouseClicked(MouseEvent e) {
            selectedPack = packIndex;
            updatePacks();
          }

          @Override
          public void mouseReleased(MouseEvent e) {}

          @Override
          public void mousePressed(MouseEvent e) {
            selectedPack = packIndex;
            updatePacks();
          }

          @Override
          public void mouseExited(MouseEvent e) {}

          @Override
          public void mouseEntered(MouseEvent e) {}
        };
    p.addMouseListener(lin);
    filler.addMouseListener(lin);
    logo.addMouseListener(lin);
    p.add(filler);
    p.add(logo);
    packPanels.add(p);
    packs.add(p);
    if (origin.equals("All")) {
      packs.setMinimumSize(new Dimension(420, (ModPack.getPackArray().size() * 55)));
      packs.setPreferredSize(new Dimension(420, (ModPack.getPackArray().size() * 55)));
    } else {
      packs.setMinimumSize(new Dimension(420, (currentPacks.size() * 55)));
      packs.setPreferredSize(new Dimension(420, (currentPacks.size() * 55)));
    }
    packsScroll.revalidate();
  }
  /** Constructor for the class, sets up two fresh tabbed text areas for program feedback. */
  public MessagesPane() {
    super();
    this.setMinimumSize(new Dimension(0, 0));
    assemble = new JTextArea();
    run = new JTextArea();
    assemble.setEditable(false);
    run.setEditable(false);
    // Set both text areas to mono font.  For assemble
    // pane, will make messages more readable.  For run
    // pane, will allow properly aligned "text graphics"
    // DPS 15 Dec 2008
    Font monoFont = new Font(Font.MONOSPACED, Font.PLAIN, 12);
    assemble.setFont(monoFont);
    run.setFont(monoFont);

    JButton assembleTabClearButton = new JButton("Clear");
    assembleTabClearButton.setToolTipText("Clear the Mars Messages area");
    assembleTabClearButton.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            assemble.setText("");
          }
        });
    assembleTab = new JPanel(new BorderLayout());
    assembleTab.add(createBoxForButton(assembleTabClearButton), BorderLayout.WEST);
    assembleTab.add(
        new JScrollPane(
            assemble,
            ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED,
            ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED),
        BorderLayout.CENTER);
    assemble.addMouseListener(
        new MouseAdapter() {
          public void mouseClicked(MouseEvent e) {
            String text;
            int lineStart = 0;
            int lineEnd = 0;
            try {
              int line = assemble.getLineOfOffset(assemble.viewToModel(e.getPoint()));
              lineStart = assemble.getLineStartOffset(line);
              lineEnd = assemble.getLineEndOffset(line);
              text = assemble.getText(lineStart, lineEnd - lineStart);
            } catch (BadLocationException ble) {
              text = "";
            }
            if (text.length() > 0) {
              // If error or warning, parse out the line and column number.
              if (text.startsWith(ErrorList.ERROR_MESSAGE_PREFIX)
                  || text.startsWith(ErrorList.WARNING_MESSAGE_PREFIX)) {
                assemble.select(lineStart, lineEnd);
                assemble.setSelectionColor(Color.YELLOW);
                assemble.repaint();
                int separatorPosition = text.indexOf(ErrorList.MESSAGE_SEPARATOR);
                if (separatorPosition >= 0) {
                  text = text.substring(0, separatorPosition);
                }
                String[] stringTokens = text.split("\\s"); // tokenize with whitespace delimiter
                String lineToken = ErrorList.LINE_PREFIX.trim();
                String columnToken = ErrorList.POSITION_PREFIX.trim();
                String lineString = "";
                String columnString = "";
                for (int i = 0; i < stringTokens.length; i++) {
                  if (stringTokens[i].equals(lineToken) && i < stringTokens.length - 1)
                    lineString = stringTokens[i + 1];
                  if (stringTokens[i].equals(columnToken) && i < stringTokens.length - 1)
                    columnString = stringTokens[i + 1];
                }
                int line = 0;
                int column = 0;
                try {
                  line = Integer.parseInt(lineString);
                } catch (NumberFormatException nfe) {
                  line = 0;
                }
                try {
                  column = Integer.parseInt(columnString);
                } catch (NumberFormatException nfe) {
                  column = 0;
                }
                // everything between FILENAME_PREFIX and LINE_PREFIX is filename.
                int fileNameStart =
                    text.indexOf(ErrorList.FILENAME_PREFIX) + ErrorList.FILENAME_PREFIX.length();
                int fileNameEnd = text.indexOf(ErrorList.LINE_PREFIX);
                String fileName = "";
                if (fileNameStart < fileNameEnd
                    && fileNameStart >= ErrorList.FILENAME_PREFIX.length()) {
                  fileName = text.substring(fileNameStart, fileNameEnd).trim();
                }
                if (fileName != null && fileName.length() > 0) {
                  selectEditorTextLine(fileName, line, column);
                  selectErrorMessage(fileName, line, column);
                }
              }
            }
          }
        });

    JButton runTabClearButton = new JButton("Clear");
    runTabClearButton.setToolTipText("Clear the Run I/O area");
    runTabClearButton.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            run.setText("");
          }
        });
    runTab = new JPanel(new BorderLayout());
    runTab.add(createBoxForButton(runTabClearButton), BorderLayout.WEST);
    runTab.add(
        new JScrollPane(
            run,
            ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED,
            ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED),
        BorderLayout.CENTER);
    this.addTab("Mars Messages", assembleTab);
    this.addTab("Run I/O", runTab);
    this.setToolTipTextAt(
        0,
        "Messages produced by Run menu. Click on assemble error message to select erroneous line");
    this.setToolTipTextAt(1, "Simulated MIPS console input and output");
  }
Exemplo n.º 17
0
    private void initialize(String message, Exception exc) {
        double[][] dLay = {
                { border, TableLayout.PREFERRED, border, TableLayout.FILL, border },
                { border, TableLayout.PREFERRED, border, TableLayout.PREFERRED, TableLayout.PREFERRED, TableLayout.FILL, border, TableLayout.PREFERRED, border }
        };
        
        contentPane = new JPanel(new TableLayout(dLay));
        
        boxButtons = Box.createHorizontalBox();
        btnOK = new JButton(Utils._("OK"));
        btnOK.addActionListener(this);
        btnDetails = new JButton(Utils._("Details") + " >>");
        btnDetails.addActionListener(this);
        btnCopy = new JButton(Utils._("Copy"), Utils.loadIcon("general/Copy"));
        btnCopy.addActionListener(this);
        
        boxButtons.add(Box.createHorizontalGlue());
        boxButtons.add(btnOK);
        boxButtons.add(Box.createHorizontalStrut(border));
        boxButtons.add(btnDetails);
        boxButtons.add(Box.createHorizontalStrut(border));
        boxButtons.add(btnCopy);
        boxButtons.add(Box.createHorizontalGlue());
        
        JLabel lblIcon = new JLabel(UIManager.getIcon("OptionPane.errorIcon"));
        
        lblText = new JLabel("<html>" + message + "</html>");
        adjustTextLabelSize(lblText);
        
        String localizedMessage = exc.getLocalizedMessage();
        if (localizedMessage == null) {
            localizedMessage = exc.getMessage();
        }
        if (localizedMessage != null) {
            lblExceptionText = new JLabel("<html>" + localizedMessage + "</html>");
            lblExceptionText.setVerticalAlignment(SwingConstants.TOP);
            adjustTextLabelSize(lblExceptionText);
        } else {
            lblExceptionText = null;
        }
        
        strutStacktrace = Box.createVerticalStrut(20);
        
        StringWriter stringBuf = new StringWriter();
        exc.printStackTrace(new PrintWriter(stringBuf));
        
        //Append some system info:
        stringBuf.append("\n\n");
        stringBuf.append(Utils.AppShortName).append(' ').append(Utils.AppVersion).append('\n');
        stringBuf.append("Java ")
            .append(System.getProperty("java.version")).append(" (")
            .append(System.getProperty("java.vendor")).append(")\n")
            .append(System.getProperty("java.runtime.name")).append(' ')
            .append(System.getProperty("java.runtime.version")).append('\n')
            .append(System.getProperty("java.vm.name")).append('\n');
        stringBuf
            .append(System.getProperty("os.name")).append(' ')
            .append(System.getProperty("os.version")).append(" (")
            .append(System.getProperty("os.arch")).append(")\n");
        
        String stacktrace = stringBuf.toString();
        
        StringBuilder sb = new StringBuilder();
        sb.append(message).append('\n');
        if (localizedMessage != null)
            sb.append(localizedMessage).append('\n');
        sb.append('\n');
        sb.append(stacktrace);
        fullMessage = sb.toString();
        
        textStacktrace = new JTextArea(stacktrace);
        textStacktrace.setFont(new Font("DialogInput", Font.PLAIN, 12));
        textStacktrace.setEditable(false);
        textStacktrace.addMouseListener(ClipboardPopup.DEFAULT_POPUP);
        textStacktrace.setRows(8);
        //textStacktrace.setColumns(40);
        
        scrollStacktrace = new JScrollPane(textStacktrace, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
        
        /*
        boxLabels = Box.createVerticalBox();
        boxLabels.add(lblText);
        boxLabels.add(Box.createVerticalStrut(border));
        if (lblExceptionText != null) {
            boxLabels.add(lblExceptionText);
            boxLabels.add(Box.createVerticalStrut(border));
        }
        boxLabels.add(scrollStacktrace);
        boxLabels.add(strutStacktrace);
        boxLabels.add(boxButtons); 
        
        contentPane.add(Box.createVerticalStrut(border), BorderLayout.NORTH);
        contentPane.add(Box.createVerticalStrut(border), BorderLayout.SOUTH);
        contentPane.add(Box.createHorizontalStrut(border), BorderLayout.WEST);
        contentPane.add(Box.createHorizontalStrut(border), BorderLayout.EAST);
        contentPane.add(boxLabels, BorderLayout.CENTER); */
        
        contentPane.add(lblIcon, "1, 1, 1, 3");
        contentPane.add(lblText, "3, 1");
        if (lblExceptionText != null)
            contentPane.add(lblExceptionText, "3, 3");
        contentPane.add(boxButtons, "1, 7, 3, 7");
        
        this.setResizable(false);
        this.getRootPane().getRootPane().setDefaultButton(btnOK);
        this.setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        this.setContentPane(contentPane);
        //this.setLocationByPlatform(true);
        
        this.pack();
//        lblText.addComponentListener(this);
//        if (lblExceptionText != null)
//            lblExceptionText.addComponentListener(this);
        
        if (Utils.debugMode) {
//            Utils.debugOut.println("EXCEPTION occured: " + message);
//            exc.printStackTrace(Utils.debugOut);
            log.log(Level.WARNING, "Exception occurred: " + message, exc);
        }
    }
Exemplo n.º 18
0
  public WSNGui(final Properties properties) {

    Preconditions.checkNotNull(properties);

    JSplitPane splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT);

    JTabbedPane tabs = new JTabbedPane();
    Dimension preferredSize = new Dimension(800, 400);

    splitPane.add(tabs);

    {
      ControllerClientView controllerClientView = new ControllerClientView();
      JScrollPane controllerClientScrollPane = new JScrollPane(controllerClientView);
      controllerClientScrollPane.setPreferredSize(preferredSize);
      new ControllerClientController(controllerClientView, properties);

      ControllerServiceView controllerServiceView = new ControllerServiceView();
      JScrollPane controllerServiceScrollPane = new JScrollPane(controllerServiceView);
      controllerClientScrollPane.setPreferredSize(preferredSize);
      new ControllerServiceController(controllerServiceView, properties);

      WSNClientView wsnClientView = new WSNClientView();
      JScrollPane wsnClientScrollPane = new JScrollPane(wsnClientView);
      wsnClientScrollPane.setPreferredSize(preferredSize);
      new WSNClientController(wsnClientView, properties);

      SessionManagementClientView sessionManagementClientView = new SessionManagementClientView();
      JScrollPane sessionManagementScrollPane = new JScrollPane(sessionManagementClientView);
      sessionManagementScrollPane.setPreferredSize(preferredSize);
      new SessionManagementClientController(sessionManagementClientView, wsnClientView, properties);

      RSClientView rsClientView = new RSClientView();
      JScrollPane rsClientScrollPane = new JScrollPane(rsClientView);
      rsClientScrollPane.setPreferredSize(preferredSize);
      new RSClientController(rsClientView, sessionManagementClientView, properties);

      SNAAClientView snaaClientView = new SNAAClientView();
      JScrollPane snaaClientScrollPane = new JScrollPane(snaaClientView);
      snaaClientScrollPane.setPreferredSize(preferredSize);
      new SNAAClientController(snaaClientView, rsClientView, properties);

      WSNServiceView wsnServiceView = new WSNServiceView();
      JScrollPane wsnServiceScrollPane = new JScrollPane(wsnServiceView);
      wsnServiceScrollPane.setPreferredSize(preferredSize);
      new WSNServiceController(wsnServiceView, properties);

      tabs.addTab("SNAA Client", snaaClientScrollPane);
      tabs.addTab("RS Client", rsClientScrollPane);
      tabs.addTab("Controller Client", controllerClientScrollPane);
      tabs.addTab("Controller Service Dummy", controllerServiceScrollPane);
      tabs.addTab("SM Client", sessionManagementScrollPane);
      tabs.addTab("WSN Client", wsnClientScrollPane);
      tabs.addTab("WSN Service Dummy", wsnServiceScrollPane);
    }

    outputTextPane = new JTextArea();
    outputTextPane.setEditable(false);
    outputTextPane.addMouseListener(
        new MouseAdapter() {
          @Override
          public void mouseClicked(final MouseEvent e) {
            if (e.getButton() == MouseEvent.BUTTON3) {
              outputTextPane.setText("");
            }
          }
        });

    JScrollPane outputScrollPane = new JScrollPane(outputTextPane);
    outputScrollPane.setPreferredSize(preferredSize);
    outputScrollPane.setAutoscrolls(true);

    splitPane.add(outputScrollPane);

    TextAreaAppender.setTextArea(outputTextPane);

    frame = new JFrame("WISEBED Web Service API Testing Tool");
    frame.setContentPane(splitPane);
    frame.pack();
  }
Exemplo n.º 19
0
  /** Creates the debug process, which is a GUI window that displays XML traffic. */
  private void createDebug() {
    frame =
        new JFrame(
            "Smack Debug Window -- " + connection.getServiceName() + ":" + connection.getPort());

    // Add listener for window closing event
    frame.addWindowListener(
        new WindowAdapter() {
          public void windowClosing(WindowEvent evt) {
            rootWindowClosing(evt);
          }
        });

    // We'll arrange the UI into four tabs. The first tab contains all data, the second
    // client generated XML, the third server generated XML, and the fourth is packet
    // data from the server as seen by Smack.
    JTabbedPane tabbedPane = new JTabbedPane();

    JPanel allPane = new JPanel();
    allPane.setLayout(new GridLayout(3, 1));
    tabbedPane.add("All", allPane);

    // Create UI elements for client generated XML traffic.
    final JTextArea sentText1 = new JTextArea();
    final JTextArea sentText2 = new JTextArea();
    sentText1.setEditable(false);
    sentText2.setEditable(false);
    sentText1.setForeground(new Color(112, 3, 3));
    sentText2.setForeground(new Color(112, 3, 3));
    allPane.add(new JScrollPane(sentText1));
    tabbedPane.add("Sent", new JScrollPane(sentText2));

    // Add pop-up menu.
    JPopupMenu menu = new JPopupMenu();
    JMenuItem menuItem1 = new JMenuItem("Copy");
    menuItem1.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            // Get the clipboard
            Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
            // Set the sent text as the new content of the clipboard
            clipboard.setContents(new StringSelection(sentText1.getText()), null);
          }
        });

    JMenuItem menuItem2 = new JMenuItem("Clear");
    menuItem2.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            sentText1.setText("");
            sentText2.setText("");
          }
        });

    // Add listener to the text area so the popup menu can come up.
    MouseListener popupListener = new PopupListener(menu);
    sentText1.addMouseListener(popupListener);
    sentText2.addMouseListener(popupListener);
    menu.add(menuItem1);
    menu.add(menuItem2);

    // Create UI elements for server generated XML traffic.
    final JTextArea receivedText1 = new JTextArea();
    final JTextArea receivedText2 = new JTextArea();
    receivedText1.setEditable(false);
    receivedText2.setEditable(false);
    receivedText1.setForeground(new Color(6, 76, 133));
    receivedText2.setForeground(new Color(6, 76, 133));
    allPane.add(new JScrollPane(receivedText1));
    tabbedPane.add("Received", new JScrollPane(receivedText2));

    // Add pop-up menu.
    menu = new JPopupMenu();
    menuItem1 = new JMenuItem("Copy");
    menuItem1.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            // Get the clipboard
            Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
            // Set the sent text as the new content of the clipboard
            clipboard.setContents(new StringSelection(receivedText1.getText()), null);
          }
        });

    menuItem2 = new JMenuItem("Clear");
    menuItem2.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            receivedText1.setText("");
            receivedText2.setText("");
          }
        });

    // Add listener to the text area so the popup menu can come up.
    popupListener = new PopupListener(menu);
    receivedText1.addMouseListener(popupListener);
    receivedText2.addMouseListener(popupListener);
    menu.add(menuItem1);
    menu.add(menuItem2);

    // Create UI elements for interpreted XML traffic.
    final JTextArea interpretedText1 = new JTextArea();
    final JTextArea interpretedText2 = new JTextArea();
    interpretedText1.setEditable(false);
    interpretedText2.setEditable(false);
    interpretedText1.setForeground(new Color(1, 94, 35));
    interpretedText2.setForeground(new Color(1, 94, 35));
    allPane.add(new JScrollPane(interpretedText1));
    tabbedPane.add("Interpreted", new JScrollPane(interpretedText2));

    // Add pop-up menu.
    menu = new JPopupMenu();
    menuItem1 = new JMenuItem("Copy");
    menuItem1.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            // Get the clipboard
            Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
            // Set the sent text as the new content of the clipboard
            clipboard.setContents(new StringSelection(interpretedText1.getText()), null);
          }
        });

    menuItem2 = new JMenuItem("Clear");
    menuItem2.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            interpretedText1.setText("");
            interpretedText2.setText("");
          }
        });

    // Add listener to the text area so the popup menu can come up.
    popupListener = new PopupListener(menu);
    interpretedText1.addMouseListener(popupListener);
    interpretedText2.addMouseListener(popupListener);
    menu.add(menuItem1);
    menu.add(menuItem2);

    frame.getContentPane().add(tabbedPane);

    frame.setSize(550, 400);
    frame.setVisible(true);

    // Create a special Reader that wraps the main Reader and logs data to the GUI.
    ObservableReader debugReader = new ObservableReader(reader);
    readerListener =
        new ReaderListener() {
          public void read(String str) {
            int index = str.lastIndexOf(">");
            if (index != -1) {
              receivedText1.append(str.substring(0, index + 1));
              receivedText2.append(str.substring(0, index + 1));
              receivedText1.append(NEWLINE);
              receivedText2.append(NEWLINE);
              if (str.length() > index) {
                receivedText1.append(str.substring(index + 1));
                receivedText2.append(str.substring(index + 1));
              }
            } else {
              receivedText1.append(str);
              receivedText2.append(str);
            }
          }
        };
    debugReader.addReaderListener(readerListener);

    // Create a special Writer that wraps the main Writer and logs data to the GUI.
    ObservableWriter debugWriter = new ObservableWriter(writer);
    writerListener =
        new WriterListener() {
          public void write(String str) {
            sentText1.append(str);
            sentText2.append(str);
            if (str.endsWith(">")) {
              sentText1.append(NEWLINE);
              sentText2.append(NEWLINE);
            }
          }
        };
    debugWriter.addWriterListener(writerListener);

    // Assign the reader/writer objects to use the debug versions. The packet reader
    // and writer will use the debug versions when they are created.
    reader = debugReader;
    writer = debugWriter;

    // Create a thread that will listen for all incoming packets and write them to
    // the GUI. This is what we call "interpreted" packet data, since it's the packet
    // data as Smack sees it and not as it's coming in as raw XML.
    listener =
        new PacketListener() {
          public void processPacket(Packet packet) {
            interpretedText1.append(packet.toXML());
            interpretedText2.append(packet.toXML());
            interpretedText1.append(NEWLINE);
            interpretedText2.append(NEWLINE);
          }
        };
  }
Exemplo n.º 20
0
  protected JPanel createPanel() {
    textArea.setEditable(false);
    setColors(textArea);
    textArea.setFont(getMonospacedFont());
    textArea.setEditable(false);

    textArea.addMouseListener(
        new MouseAdapter() {
          public void mouseClicked(java.awt.event.MouseEvent e) {
            if (e.getButton() != MouseEvent.BUTTON3) {
              return;
            }
            String text = getTextAtLocation(textArea, e.getX(), e.getY());
            if (text != null) {
              text = text.replaceAll(Pattern.quote("\n"), "");

              final DisassembledLine line = parseDisassembledLine(text);
              toggleBreakpoint(line.getAddress());
            }
          }
        });

    textArea.addKeyListener(
        new PagingKeyAdapter() {

          @Override
          protected void onePageUp() {
            if (addressAtTopOfScreen != null && addressAtBottomOfScreen != null) {
              final Size distanceInBytes =
                  Address.calcDistanceInBytes(addressAtTopOfScreen, addressAtBottomOfScreen);
              setViewStartingAddress(addressAtTopOfScreen.minus(distanceInBytes), false);
            }
          }

          @Override
          protected void onePageDown() {
            if (addressAtTopOfScreen != null && addressAtBottomOfScreen != null) {
              final Size distanceInBytes =
                  Address.calcDistanceInBytes(addressAtTopOfScreen, addressAtBottomOfScreen);
              setViewStartingAddress(addressAtTopOfScreen.plus(distanceInBytes, true), false);
            }
          }

          @Override
          protected void oneLineUp() {
            if (addressAtTopOfScreen != null) {
              setViewStartingAddress(addressAtTopOfScreen.minus(WordAddress.wordAddress(1)), false);
            }
          }

          @Override
          protected void oneLineDown() {

            if (addressAtBottomOfScreen != null && addressAtTopOfScreen != null) {
              final int instructionSize =
                  Emulator.calculateInstructionSizeInWords(
                      addressAtBottomOfScreen, emulator.getMemory());
              setViewStartingAddress(
                  addressAtTopOfScreen.plus(Size.words(instructionSize), true), false);
            }
          }
        });

    // setup top panel
    final JPanel controlPanel = emulatorController.getPanel(getViewContainer());

    // setup bottom panel
    final JPanel bottomPanel = new JPanel();
    setColors(bottomPanel);
    bottomPanel.setLayout(new GridBagLayout());
    GridBagConstraints cnstrs = constraints(0, 0, true, true, GridBagConstraints.BOTH);
    bottomPanel.add(textArea, cnstrs);

    // ======== setup result panel ===========

    final JPanel result = new JPanel();
    result.addComponentListener(
        new ComponentAdapter() {
          @Override
          public void componentResized(ComponentEvent e) {
            refreshDisplay();
          }
        });
    setColors(result);
    result.setLayout(new GridBagLayout());

    cnstrs = constraints(0, 0, true, false, GridBagConstraints.HORIZONTAL);
    result.add(controlPanel, cnstrs);
    cnstrs = constraints(0, 1, true, true, GridBagConstraints.BOTH);
    result.add(bottomPanel, cnstrs);
    return result;
  }
Exemplo n.º 21
0
  /** Layout the console frame */
  private void createFrame() {
    // Use a JmriJFrame to ensure that we fit on the screen
    frame = new JmriJFrame(Bundle.getMessage("TitleConsole"));

    pref = jmri.InstanceManager.getDefault(jmri.UserPreferencesManager.class);

    // Add Help menu (Windows menu automaitically added)
    frame.addHelpMenu("package.apps.SystemConsole", true); // NOI18N

    // Grab a reference to the system clipboard
    final Clipboard clipboard = frame.getToolkit().getSystemClipboard();

    // Setup the scroll pane
    JScrollPane scroll = new JScrollPane(console);
    frame.add(scroll, BorderLayout.CENTER);

    // Add button to allow copy to clipboard
    JPanel p = new JPanel();
    JButton copy = new JButton(Bundle.getMessage("ButtonCopyClip"));
    copy.addActionListener(
        (ActionEvent event) -> {
          StringSelection text = new StringSelection(console.getText());
          clipboard.setContents(text, text);
        });
    p.add(copy);

    // Add button to allow console window to be closed
    JButton close = new JButton(Bundle.getMessage("ButtonClose"));
    close.addActionListener(
        (ActionEvent event) -> {
          frame.setVisible(false);
          frame.dispose();
        });
    p.add(close);

    JButton stackTrace = new JButton(Bundle.getMessage("ButtonStackTrace"));
    stackTrace.addActionListener(
        (ActionEvent event) -> {
          performStackTrace();
        });
    p.add(stackTrace);

    // Add checkbox to enable/disable auto-scrolling
    // Use the inverted SimplePreferenceState to default as enabled
    p.add(
        autoScroll =
            new JCheckBox(
                Bundle.getMessage("CheckBoxAutoScroll"),
                !pref.getSimplePreferenceState(alwaysScrollCheck)));
    autoScroll.addActionListener(
        (ActionEvent event) -> {
          doAutoScroll(console, autoScroll.isSelected());
          pref.setSimplePreferenceState(alwaysScrollCheck, !autoScroll.isSelected());
        });

    // Add checkbox to enable/disable always on top
    p.add(
        alwaysOnTop =
            new JCheckBox(
                Bundle.getMessage("CheckBoxOnTop"),
                pref.getSimplePreferenceState(alwaysOnTopCheck)));
    alwaysOnTop.setVisible(true);
    alwaysOnTop.setToolTipText(Bundle.getMessage("ToolTipOnTop"));
    alwaysOnTop.addActionListener(
        (ActionEvent event) -> {
          frame.setAlwaysOnTop(alwaysOnTop.isSelected());
          pref.setSimplePreferenceState(alwaysOnTopCheck, alwaysOnTop.isSelected());
        });

    frame.setAlwaysOnTop(alwaysOnTop.isSelected());

    // Define the pop-up menu
    copySelection = new JMenuItem(Bundle.getMessage("MenuItemCopy"));
    copySelection.addActionListener(
        (ActionEvent event) -> {
          StringSelection text = new StringSelection(console.getSelectedText());
          clipboard.setContents(text, text);
        });
    popup.add(copySelection);

    JMenuItem menuItem = new JMenuItem(Bundle.getMessage("ButtonCopyClip"));
    menuItem.addActionListener(
        (ActionEvent event) -> {
          StringSelection text = new StringSelection(console.getText());
          clipboard.setContents(text, text);
        });
    popup.add(menuItem);

    popup.add(new JSeparator());

    JRadioButtonMenuItem rbMenuItem;

    // Define the colour scheme sub-menu
    schemeMenu = new JMenu(rbc.getString("ConsoleSchemeMenu"));
    schemeGroup = new ButtonGroup();
    for (final Scheme s : schemes) {
      rbMenuItem = new JRadioButtonMenuItem(s.description);
      rbMenuItem.addActionListener(
          (ActionEvent event) -> {
            setScheme(schemes.indexOf(s));
          });
      rbMenuItem.setSelected(getScheme() == schemes.indexOf(s));
      schemeMenu.add(rbMenuItem);
      schemeGroup.add(rbMenuItem);
    }
    popup.add(schemeMenu);

    // Define the wrap style sub-menu
    wrapMenu = new JMenu(rbc.getString("ConsoleWrapStyleMenu"));
    wrapGroup = new ButtonGroup();
    rbMenuItem = new JRadioButtonMenuItem(rbc.getString("ConsoleWrapStyleNone"));
    rbMenuItem.addActionListener(
        (ActionEvent event) -> {
          setWrapStyle(WRAP_STYLE_NONE);
        });
    rbMenuItem.setSelected(getWrapStyle() == WRAP_STYLE_NONE);
    wrapMenu.add(rbMenuItem);
    wrapGroup.add(rbMenuItem);

    rbMenuItem = new JRadioButtonMenuItem(rbc.getString("ConsoleWrapStyleLine"));
    rbMenuItem.addActionListener(
        (ActionEvent event) -> {
          setWrapStyle(WRAP_STYLE_LINE);
        });
    rbMenuItem.setSelected(getWrapStyle() == WRAP_STYLE_LINE);
    wrapMenu.add(rbMenuItem);
    wrapGroup.add(rbMenuItem);

    rbMenuItem = new JRadioButtonMenuItem(rbc.getString("ConsoleWrapStyleWord"));
    rbMenuItem.addActionListener(
        (ActionEvent event) -> {
          setWrapStyle(WRAP_STYLE_WORD);
        });
    rbMenuItem.setSelected(getWrapStyle() == WRAP_STYLE_WORD);
    wrapMenu.add(rbMenuItem);
    wrapGroup.add(rbMenuItem);

    popup.add(wrapMenu);

    // Bind pop-up to objects
    MouseListener popupListener = new PopupListener();
    console.addMouseListener(popupListener);
    frame.addMouseListener(popupListener);

    // Add document listener to scroll to end when modified if required
    console
        .getDocument()
        .addDocumentListener(
            new DocumentListener() {

              // References to the JTextArea and JCheckBox
              // of this instantiation
              JTextArea ta = console;
              JCheckBox chk = autoScroll;

              @Override
              public void insertUpdate(DocumentEvent e) {
                doAutoScroll(ta, chk.isSelected());
              }

              @Override
              public void removeUpdate(DocumentEvent e) {
                doAutoScroll(ta, chk.isSelected());
              }

              @Override
              public void changedUpdate(DocumentEvent e) {
                doAutoScroll(ta, chk.isSelected());
              }
            });

    // Add the button panel to the frame & then arrange everything
    frame.add(p, BorderLayout.SOUTH);
    frame.pack();
  }
Exemplo n.º 22
0
  /*
   * GUI Code to add a modpack to the selection
   */
  public void addPack(final ModPack pack) {
    if (!modPacksAdded) {
      modPacksAdded = true;
      packs.removeAll();
      packs.repaint();
    }
    final int packIndex = packPanels.size();
    final JPanel p = new JPanel();
    p.setBounds(0, (packIndex * 55), 420, 55);
    p.setLayout(null);
    JLabel logo = new JLabel(new ImageIcon(pack.getLogo()));
    logo.setBounds(6, 6, 42, 42);
    logo.setVisible(true);

    JTextArea filler =
        new JTextArea(
            pack.getName()
                + " (v"
                + pack.getVersion()
                + ") Minecraft Version "
                + pack.getMcVersion()
                + "\n"
                + "By "
                + pack.getAuthor());
    filler.setBorder(null);
    filler.setEditable(false);
    filler.setForeground(LauncherStyle.getCurrentStyle().tabPaneForeground);
    filler.setBounds(58, 6, 362, 42);
    filler.setBackground(LauncherStyle.getCurrentStyle().tabPaneBackground);

    MouseAdapter lin =
        new MouseAdapter() {
          @Override
          public void mouseClicked(MouseEvent e) {
            if (e.getClickCount() == 2) {
              LaunchFrame.getInstance().doLaunch();
            }
          }

          @Override
          public void mousePressed(MouseEvent e) {
            selectedPack = packIndex;
            updatePacks();
          }
        };
    p.addMouseListener(lin);
    filler.addMouseListener(lin);
    logo.addMouseListener(lin);
    p.add(filler);
    p.add(logo);
    packPanels.add(p);
    packs.add(p);

    packs.setMinimumSize(new Dimension(420, (packPanels.size() * 55)));
    packs.setPreferredSize(new Dimension(420, (packPanels.size() * 55)));

    //
    // packsScroll.revalidate();
    if (pack.getDir().equalsIgnoreCase(getLastPack())) {
      selectedPack = packIndex;
    }
  }
Exemplo n.º 23
0
  /** Create the panel. */
  public LC3View() {
    setLayout(null);

    JPanel panel = new JPanel();
    panel.setBorder(new BevelBorder(BevelBorder.LOWERED, null, null, null, null));
    panel.setBounds(31, 29, 192, 229);
    add(panel);
    panel.setLayout(null);

    r0 = new JTextField();
    r0.setHorizontalAlignment(SwingConstants.CENTER);
    r0.setFont(new Font("Lucida Grande", Font.PLAIN, 13));
    r0.setEditable(false);
    r0.setFocusable(false);
    r0.setBounds(46, 10, 70, 26);
    panel.add(r0);
    r0.setColumns(10);

    JLabel lblR = new JLabel("R0");
    lblR.setFocusable(false);
    lblR.setBounds(21, 16, 25, 16);
    panel.add(lblR);

    r2 = new JTextField();
    r2.setHorizontalAlignment(SwingConstants.CENTER);
    r2.setFont(new Font("Lucida Grande", Font.PLAIN, 13));
    r2.setEditable(false);
    r2.setFocusable(false);
    r2.setColumns(10);
    r2.setBounds(46, 62, 70, 26);
    panel.add(r2);

    JLabel lblR_2 = new JLabel("R2");
    lblR_2.setFocusable(false);
    lblR_2.setBounds(21, 68, 25, 16);
    panel.add(lblR_2);

    r1 = new JTextField();
    r1.setHorizontalAlignment(SwingConstants.CENTER);
    r1.setFont(new Font("Lucida Grande", Font.PLAIN, 13));
    r1.setEditable(false);
    r1.setFocusable(false);
    r1.setColumns(10);
    r1.setBounds(46, 36, 70, 26);
    panel.add(r1);

    JLabel lblR_1 = new JLabel("R1");
    lblR_1.setFocusable(false);
    lblR_1.setBounds(21, 42, 25, 16);
    panel.add(lblR_1);

    r3 = new JTextField();
    r3.setHorizontalAlignment(SwingConstants.CENTER);
    r3.setFont(new Font("Lucida Grande", Font.PLAIN, 13));
    r3.setEditable(false);
    r3.setFocusable(false);
    r3.setColumns(10);
    r3.setBounds(46, 88, 70, 26);
    panel.add(r3);

    JLabel lblR_3 = new JLabel("R3");
    lblR_3.setFocusable(false);
    lblR_3.setBounds(21, 94, 25, 16);
    panel.add(lblR_3);

    r4 = new JTextField();
    r4.setHorizontalAlignment(SwingConstants.CENTER);
    r4.setFont(new Font("Lucida Grande", Font.PLAIN, 13));
    r4.setEditable(false);
    r4.setFocusable(false);
    r4.setColumns(10);
    r4.setBounds(46, 114, 70, 26);
    panel.add(r4);

    JLabel lblR_4 = new JLabel("R4");
    lblR_4.setFocusable(false);
    lblR_4.setBounds(21, 120, 25, 16);
    panel.add(lblR_4);

    r5 = new JTextField();
    r5.setHorizontalAlignment(SwingConstants.CENTER);
    r5.setFont(new Font("Lucida Grande", Font.PLAIN, 13));
    r5.setEditable(false);
    r5.setFocusable(false);
    r5.setColumns(10);
    r5.setBounds(46, 140, 70, 26);
    panel.add(r5);

    JLabel lblR_5 = new JLabel("R5");
    lblR_5.setFocusable(false);
    lblR_5.setBounds(21, 146, 25, 16);
    panel.add(lblR_5);

    r6 = new JTextField();
    r6.setHorizontalAlignment(SwingConstants.CENTER);
    r6.setFont(new Font("Lucida Grande", Font.PLAIN, 13));
    r6.setEditable(false);
    r6.setFocusable(false);
    r6.setColumns(10);
    r6.setBounds(46, 166, 70, 26);
    panel.add(r6);

    JLabel lblR_6 = new JLabel("R6");
    lblR_6.setFocusable(false);
    lblR_6.setBounds(21, 172, 25, 16);
    panel.add(lblR_6);

    r7 = new JTextField();
    r7.setHorizontalAlignment(SwingConstants.CENTER);
    r7.setFont(new Font("Lucida Grande", Font.PLAIN, 13));
    r7.setEditable(false);
    r7.setFocusable(false);
    r7.setColumns(10);
    r7.setBounds(46, 192, 70, 26);
    panel.add(r7);

    JLabel lblR_7 = new JLabel("R7");
    lblR_7.setFocusable(false);
    lblR_7.setBounds(21, 198, 25, 16);
    panel.add(lblR_7);

    d0 = new JTextField();
    d0.setText("0");
    d0.setHorizontalAlignment(SwingConstants.RIGHT);
    d0.setFont(new Font("Lucida Grande", Font.PLAIN, 13));
    d0.setFocusable(false);
    d0.setEditable(false);
    d0.setColumns(10);
    d0.setBounds(118, 10, 62, 26);
    panel.add(d0);

    d1 = new JTextField();
    d1.setText("0");
    d1.setHorizontalAlignment(SwingConstants.RIGHT);
    d1.setFont(new Font("Lucida Grande", Font.PLAIN, 13));
    d1.setFocusable(false);
    d1.setEditable(false);
    d1.setColumns(10);
    d1.setBounds(118, 36, 62, 26);
    panel.add(d1);

    d2 = new JTextField();
    d2.setText("0");
    d2.setHorizontalAlignment(SwingConstants.RIGHT);
    d2.setFont(new Font("Lucida Grande", Font.PLAIN, 13));
    d2.setFocusable(false);
    d2.setEditable(false);
    d2.setColumns(10);
    d2.setBounds(118, 62, 62, 26);
    panel.add(d2);

    d3 = new JTextField();
    d3.setText("0");
    d3.setHorizontalAlignment(SwingConstants.RIGHT);
    d3.setFont(new Font("Lucida Grande", Font.PLAIN, 13));
    d3.setFocusable(false);
    d3.setEditable(false);
    d3.setColumns(10);
    d3.setBounds(118, 88, 62, 26);
    panel.add(d3);

    d4 = new JTextField();
    d4.setText("0");
    d4.setHorizontalAlignment(SwingConstants.RIGHT);
    d4.setFont(new Font("Lucida Grande", Font.PLAIN, 13));
    d4.setFocusable(false);
    d4.setEditable(false);
    d4.setColumns(10);
    d4.setBounds(118, 114, 62, 26);
    panel.add(d4);

    d5 = new JTextField();
    d5.setText("0");
    d5.setHorizontalAlignment(SwingConstants.RIGHT);
    d5.setFont(new Font("Lucida Grande", Font.PLAIN, 13));
    d5.setFocusable(false);
    d5.setEditable(false);
    d5.setColumns(10);
    d5.setBounds(118, 140, 62, 26);
    panel.add(d5);

    d6 = new JTextField();
    d6.setText("0");
    d6.setHorizontalAlignment(SwingConstants.RIGHT);
    d6.setFont(new Font("Lucida Grande", Font.PLAIN, 13));
    d6.setFocusable(false);
    d6.setEditable(false);
    d6.setColumns(10);
    d6.setBounds(118, 166, 62, 26);
    panel.add(d6);

    d7 = new JTextField();
    d7.setText("0");
    d7.setHorizontalAlignment(SwingConstants.RIGHT);
    d7.setFont(new Font("Lucida Grande", Font.PLAIN, 13));
    d7.setFocusable(false);
    d7.setEditable(false);
    d7.setColumns(10);
    d7.setBounds(118, 192, 62, 26);
    panel.add(d7);

    JButton btnReset = new JButton("Reset");
    btnReset.setFocusable(false);
    btnReset.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            machine.reset();
            console.setText("");
            update();
          }
        });
    btnReset.setBounds(55, 369, 99, 29);
    add(btnReset);

    btnStep = new JButton("Step");
    btnStep.setFocusable(false);
    btnStep.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            machine.step();
            update();
          }
        });
    btnStep.setBounds(9, 400, 99, 29);
    add(btnStep);

    btnStepOver = new JButton("Step Over");
    btnStepOver.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            status.setText("running...");
            memView.select(0, 0);
            btnStep.setEnabled(false);
            btnStepOver.setEnabled(false);
            btnRun.setEnabled(false);
            btnStop.setEnabled(true);
            machine.stepOver();
          }
        });
    btnStepOver.setBounds(104, 400, 92, 29);
    add(btnStepOver);

    btnRun = new JButton("Run");
    btnRun.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            status.setText("running...");
            memView.select(0, 0);
            btnStep.setEnabled(false);
            btnStepOver.setEnabled(false);
            btnRun.setEnabled(false);
            btnStop.setEnabled(true);
            machine.run();
          }
        });
    btnRun.setBounds(9, 432, 99, 29);
    add(btnRun);

    btnStop = new JButton("Stop");
    btnStop.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            machine.stop();
          }
        });
    btnStop.setBounds(104, 432, 99, 29);
    add(btnStop);

    JScrollPane memScroll = new JScrollPane();
    memScroll.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
    memScroll.setBorder(new BevelBorder(BevelBorder.LOWERED, null, null, null, null));
    memScroll.setBounds(235, 29, 421, 485);
    add(memScroll);

    memView = new JTextArea();
    memView.addMouseListener(
        new MouseAdapter() {
          @Override
          public void mouseReleased(MouseEvent e) {
            if (e.getClickCount() == 2) {
              int line = getLine(memView.getText(), memView.getCaretPosition());
              machine.toggleBreakPnt(line);
            }
            update();
          }
        });
    memView.setEditable(false);
    memView.setFont(new Font("Courier New", Font.PLAIN, 13));
    memScroll.setViewportView(memView);

    JLabel lblStatus = new JLabel("Status:");
    lblStatus.setBounds(17, 541, 50, 16);
    add(lblStatus);

    status = new JTextField();
    status.setBorder(new BevelBorder(BevelBorder.LOWERED, null, null, null, null));
    status.setBounds(67, 536, 589, 26);
    add(status);
    status.setColumns(10);

    JPanel panel_1 = new JPanel();
    panel_1.setBorder(new BevelBorder(BevelBorder.LOWERED, null, null, null, null));
    panel_1.setBounds(31, 270, 123, 71);
    add(panel_1);
    panel_1.setLayout(null);

    cbNeg = new JCheckBox("Neg");
    cbNeg.setFocusable(false);
    cbNeg.setBounds(28, 6, 57, 23);
    panel_1.add(cbNeg);

    cbZero = new JCheckBox("Zero");
    cbZero.setFocusable(false);
    cbZero.setSelected(true);
    cbZero.setBounds(28, 25, 60, 23);
    panel_1.add(cbZero);

    cbPos = new JCheckBox("Pos");
    cbPos.setFocusable(false);
    cbPos.setBounds(28, 43, 54, 23);
    panel_1.add(cbPos);

    JButton btnLoadProgram = new JButton("Load Program");
    btnLoadProgram.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {

            JFileChooser fileChooser = new JFileChooser();
            if (currentDir != null) fileChooser.setCurrentDirectory(currentDir);
            fileChooser.setFileFilter(
                new FileNameExtensionFilter("Prolog Files", new String[] {"lc3"}));
            if (fileChooser.showOpenDialog(memView) == JFileChooser.APPROVE_OPTION) {
              File file = fileChooser.getSelectedFile();
              try {
                machine.loadProgram(file.getAbsolutePath());
                update();
                JFrame frame =
                    (JFrame)
                        memView
                            .getParent()
                            .getParent()
                            .getParent()
                            .getParent()
                            .getParent()
                            .getParent()
                            .getParent();
                frame.setTitle("LC3 Simulator    " + machine.programName());
                currentDir = file.getParentFile();
              } catch (Exception error) {
              }
            }
          }
        });
    btnLoadProgram.setBounds(48, 473, 117, 29);
    add(btnLoadProgram);

    console = new JTextArea();
    console.addMouseListener(
        new MouseAdapter() {
          @Override
          public void mouseReleased(MouseEvent e) {
            memView.setCaretPosition(console.getText().length());
          }
        });
    console.addKeyListener(
        new KeyAdapter() {
          @Override
          public void keyTyped(KeyEvent e) {
            char c = e.getKeyChar();
            e.consume();
            machine.consoleNewChar(c);
          }

          @Override
          public void keyPressed(KeyEvent e) {
            if (e.getKeyChar() == '\n') e.consume();
          }
        });
    console.setBorder(new BevelBorder(BevelBorder.LOWERED, null, null, null, null));
    console.setBounds(69, 574, 589, 145);
    add(console);

    JLabel lblConsole = new JLabel("Console:");
    lblConsole.setBounds(9, 574, 58, 16);
    add(lblConsole);

    machine = new LC3(this);
    update();
  }
Exemplo n.º 24
0
  public ProcessFrame(Properties theProperties) {
    super(new BorderLayout());
    // myFile = theFile;
    myProperties = theProperties;
    Properties props = System.getProperties();
    props.put("http.proxyHost", myProperties.getProperty("PROXYHOST"));
    props.put("http.proxyPort", myProperties.getProperty("PROXYPORT"));

    // Create the demo's UI.
    StartButton = new JButton("Start");
    StartButton.setActionCommand("start");
    StartButton.addActionListener(this);
    cancelButton = new JButton("Cancel");
    cancelButton.setActionCommand("cancel");
    cancelButton.addActionListener(this);
    cancelButton.setEnabled(false);

    myDownloadOptions = new JComboBox(myDownloadOptionsStr);

    progressBar = new JProgressBar(0, 100);
    progressBar.setValue(0);
    progressBar.setStringPainted(true);
    progressBar2 = new JProgressBar(0, 100);
    progressBar2.setValue(0);
    progressBar2.setStringPainted(true);
    progressBar3 = new JProgressBar(0, 100);
    progressBar4 = new JProgressBar(0, 100);
    progressBar5 = new JProgressBar(0, 100);
    progressBar3.setValue(0);
    progressBar3.setStringPainted(true);
    progressBar4.setValue(0);
    progressBar4.setStringPainted(true);
    progressBar5.setValue(0);
    progressBar5.setStringPainted(true);

    taskOutput = new JTextArea(5, 20);

    final JPopupMenu taskPopupMenu = new JPopupMenu();
    JMenuItem clearMenuItem = new JMenuItem("Clear");
    clearMenuItem.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent actionEvent) {
            if (actionEvent.getActionCommand().equals("Clear")) {
              taskOutput.setText("");
            }
          }
        });
    taskPopupMenu.add(clearMenuItem);
    taskOutput.setMargin(new Insets(5, 5, 5, 5));
    taskOutput.setEditable(false);
    taskOutput.addMouseListener(
        new MouseAdapter() {
          private void showIfPopupTrigger(MouseEvent mouseEvent) {
            if (mouseEvent.isPopupTrigger()) {
              taskPopupMenu.show(mouseEvent.getComponent(), mouseEvent.getX(), mouseEvent.getY());
            }
          }

          public void mousePressed(MouseEvent mouseEvent) {
            showIfPopupTrigger(mouseEvent);
          }

          public void mouseReleased(MouseEvent mouseEvent) {
            showIfPopupTrigger(mouseEvent);
          }
        });

    JPanel panel = new JPanel();
    JPanel panel2 = new JPanel();
    panel.setLayout(new GridBagLayout());
    panel2.setLayout(new GridBagLayout());
    panel.add(
        progressBar4,
        new GridBagConstraints(
            2,
            1,
            1,
            1,
            0.0,
            0.0,
            GridBagConstraints.CENTER,
            GridBagConstraints.NONE,
            new Insets(11, 11, 0, 0),
            0,
            0));
    panel.add(
        new JLabel("TOTAL"),
        new GridBagConstraints(
            1,
            1,
            1,
            1,
            0.0,
            0.0,
            GridBagConstraints.CENTER,
            GridBagConstraints.BOTH,
            new Insets(0, 11, 0, 0),
            0,
            0));
    panel.add(
        progressBar,
        new GridBagConstraints(
            2,
            2,
            1,
            1,
            0.0,
            0.0,
            GridBagConstraints.CENTER,
            GridBagConstraints.NONE,
            new Insets(11, 11, 0, 0),
            0,
            0));
    panel.add(
        new JLabel("REMOTE DOWNLOAD"),
        new GridBagConstraints(
            1,
            2,
            1,
            1,
            0.0,
            0.0,
            GridBagConstraints.CENTER,
            GridBagConstraints.BOTH,
            new Insets(0, 11, 0, 0),
            0,
            0));
    panel.add(
        progressBar2,
        new GridBagConstraints(
            2,
            3,
            1,
            1,
            0.0,
            0.0,
            GridBagConstraints.CENTER,
            GridBagConstraints.NONE,
            new Insets(11, 11, 0, 0),
            0,
            0));
    panel.add(
        new JLabel("REMOTE SPLIT"),
        new GridBagConstraints(
            1,
            3,
            1,
            1,
            0.0,
            0.0,
            GridBagConstraints.CENTER,
            GridBagConstraints.BOTH,
            new Insets(0, 11, 0, 0),
            0,
            0));
    panel.add(
        progressBar3,
        new GridBagConstraints(
            2,
            4,
            1,
            1,
            0.0,
            0.0,
            GridBagConstraints.CENTER,
            GridBagConstraints.NONE,
            new Insets(11, 11, 0, 0),
            0,
            0));
    panel.add(
        new JLabel("LOCAL DOWNLOAD"),
        new GridBagConstraints(
            1,
            4,
            1,
            1,
            0.0,
            0.0,
            GridBagConstraints.CENTER,
            GridBagConstraints.BOTH,
            new Insets(0, 11, 0, 0),
            0,
            0));
    panel.add(
        progressBar5,
        new GridBagConstraints(
            2,
            5,
            1,
            1,
            0.0,
            0.0,
            GridBagConstraints.CENTER,
            GridBagConstraints.NONE,
            new Insets(11, 11, 0, 0),
            0,
            0));
    panel.add(
        new JLabel("LOCAL JOIN"),
        new GridBagConstraints(
            1,
            5,
            1,
            1,
            0.0,
            0.0,
            GridBagConstraints.CENTER,
            GridBagConstraints.BOTH,
            new Insets(0, 11, 0, 0),
            0,
            0));
    panel2.add(
        myDownloadOptions,
        new GridBagConstraints(
            1,
            1,
            1,
            1,
            0.0,
            0.0,
            GridBagConstraints.CENTER,
            GridBagConstraints.HORIZONTAL,
            new Insets(4, 13, 4, 0),
            0,
            0));
    panel2.add(
        StartButton,
        new GridBagConstraints(
            2,
            1,
            1,
            1,
            0.0,
            0.0,
            GridBagConstraints.CENTER,
            GridBagConstraints.HORIZONTAL,
            new Insets(4, 13, 4, 0),
            0,
            0));
    panel2.add(
        cancelButton,
        new GridBagConstraints(
            3,
            1,
            1,
            1,
            0.0,
            0.0,
            GridBagConstraints.CENTER,
            GridBagConstraints.HORIZONTAL,
            new Insets(4, 13, 4, 0),
            0,
            0));

    add(panel, BorderLayout.PAGE_START);
    add(panel2, BorderLayout.CENTER);
    add(new JScrollPane(taskOutput), BorderLayout.PAGE_END);

    setBorder(BorderFactory.createEmptyBorder(20, 20, 20, 20));
  }