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); }
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); }
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)); }
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; }
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); }
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(); }
/* * 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; } }
/** 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"); }
/** 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); } }; }
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)); }