// Initialize all the GUI components and display the frame private static void initGUI() { // Set up the status bar statusField = new JLabel(); statusField.setText(statusMessages[DISCONNECTED]); statusColor = new JTextField(1); statusColor.setBackground(Color.red); statusColor.setEditable(false); statusBar = new JPanel(new BorderLayout()); statusBar.add(statusColor, BorderLayout.WEST); statusBar.add(statusField, BorderLayout.CENTER); // Set up the options pane JPanel optionsPane = initOptionsPane(); // Set up the chat pane JPanel chatPane = new JPanel(new BorderLayout()); chatText = new JTextArea(10, 20); chatText.setLineWrap(true); chatText.setEditable(false); chatText.setForeground(Color.blue); JScrollPane chatTextPane = new JScrollPane( chatText, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_NEVER); chatLine = new JTextField(); chatLine.setEnabled(false); chatLine.addActionListener( new ActionAdapter() { public void actionPerformed(ActionEvent e) { String s = chatLine.getText(); if (!s.equals("")) { appendToChatBox("OUTGOING: " + s + "\n"); chatLine.selectAll(); // Send the string sendString(s); } } }); chatPane.add(chatLine, BorderLayout.SOUTH); chatPane.add(chatTextPane, BorderLayout.CENTER); chatPane.setPreferredSize(new Dimension(200, 200)); // Set up the main pane JPanel mainPane = new JPanel(new BorderLayout()); mainPane.add(statusBar, BorderLayout.SOUTH); mainPane.add(optionsPane, BorderLayout.WEST); mainPane.add(chatPane, BorderLayout.CENTER); // Set up the main frame mainFrame = new JFrame("Simple TCP Chat"); mainFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); mainFrame.setContentPane(mainPane); mainFrame.setSize(mainFrame.getPreferredSize()); mainFrame.setLocation(200, 200); mainFrame.pack(); mainFrame.setVisible(true); }
public static JTextArea getTextArea() { JTextArea component = new JTextArea(); component.setBackground(BACKGROUND_COLOR_TXTA); component.setForeground(TEXT_COLOR_TXTA); component.setFont(FONT_TYPE_TXTA); return component; }
/** Reload images and colors. */ public void loadSkin() { errorIconLabel.setIcon(new ImageIcon(ImageLoader.getImage(ImageLoader.EXCLAMATION_MARK))); if (downloadFile != null) imageLabel.setIcon(new ImageIcon(ImageLoader.getImage(ImageLoader.DEFAULT_FILE_ICON))); errorArea.setForeground(new Color(resources.getColor("service.gui.ERROR_FOREGROUND"))); }
/** * Creates the terminal for interaction with client from server * * @param s */ public Terminal(Server s) { mServer = s; TextFieldListener tfListener = new TextFieldListener(); input.addActionListener(tfListener); Display = new javax.swing.JLayeredPane(); input.setColumns(50); output.setColumns(50); output.setRows(30); output.setEditable(false); output.setBackground(Color.BLACK); output.setForeground(Color.WHITE); input.requestFocus(); // start with focus on this field output.setBounds(0, 0, 550, 310); Display.add(output, javax.swing.JLayeredPane.DEFAULT_LAYER); input.setBounds(0, 320, 550, 25); Display.add(input, javax.swing.JLayeredPane.DEFAULT_LAYER); javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); getContentPane().setLayout(layout); layout.setHorizontalGroup( layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup( layout .createSequentialGroup() .addComponent( Display, javax.swing.GroupLayout.PREFERRED_SIZE, 550, javax.swing.GroupLayout.PREFERRED_SIZE))); layout.setVerticalGroup( layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup( layout .createSequentialGroup() .addGroup( layout .createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING) .addComponent( Display, javax.swing.GroupLayout.PREFERRED_SIZE, 350, javax.swing.GroupLayout.PREFERRED_SIZE)))); pack(); }
private JPanel createTopPanel(YWorkItem item) { JPanel topPanel = new JPanel(new BorderLayout()); topPanel.setBackground(YAdminGUI._apiColour); JPanel leftPanel = new JPanel(new BorderLayout()); leftPanel.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10)); JTextArea explanatoryText = new JTextArea(); explanatoryText.setText( "The data you submitted for this work item was \n" + "validated against a schema (see below). For some reason the\n" + "this data did not succeed in passing the constrainst set\n" + "inside the schema.\n" + "Usage Note: If this is causing problems try using the Web server\n" + "version of YAWL, which supports automatic forms generation.\n" + "Otherwise you could copy the schema from this page and use it\n " + "to create a valid output document using an XML development tool."); explanatoryText.setEditable(false); explanatoryText.setFont(new Font("Arial", Font.BOLD, 12)); explanatoryText.setForeground(Color.DARK_GRAY); explanatoryText.setBackground(YAdminGUI._apiColour); leftPanel.add(explanatoryText); topPanel.add(leftPanel, BorderLayout.WEST); JPanel rightPanel = new JPanel(new GridLayout(4, 2)); rightPanel.setBackground(YAdminGUI._apiColour); rightPanel.setBorder( BorderFactory.createCompoundBorder( BorderFactory.createTitledBorder( BorderFactory.createEtchedBorder(), "Work Item Details"), BorderFactory.createEmptyBorder(10, 10, 10, 10))); YTask task = YEngine.getInstance().getTaskDefinition(item.getSpecificationID(), item.getTaskID()); String taskName = task.getName(); String[] text = { item.getSpecificationID().toString(), taskName, item.getIDString(), item.getStartTimeStr() }; String[] labels = {"Specification ID", "Task Name", "WorkItem ID", "Task Started"}; for (int i = 0; i < text.length; i++) { String s = text[i]; rightPanel.add(new JLabel(labels[i])); JTextField t = new JTextField(s); t.setEditable(false); rightPanel.add(t); } topPanel.add(rightPanel, BorderLayout.CENTER); return topPanel; }
@Override public Component getListCellRendererComponent( JList<? extends E> list, E value, int index, boolean isSelected, boolean cellHasFocus) { label.setText(Objects.toString(value, "")); this.index = index; if (isSelected) { setBackground(list.getSelectionBackground()); label.setForeground(list.getSelectionForeground()); } else { setBackground(index % 2 == 0 ? EVEN_COLOR : list.getBackground()); label.setForeground(list.getForeground()); } resetButtonStatus(); if (Objects.nonNull(button)) { if (index == pressedIndex) { button.getModel().setSelected(true); button.getModel().setArmed(true); button.getModel().setPressed(true); } else if (index == rolloverIndex) { button.getModel().setRollover(true); } } return this; }
/* **构造函数 */ public AboutDialog() { setTitle("蜘蛛牌"); setSize(300, 200); setResizable(false); setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); Container c = this.getContentPane(); jt1.setSize(260, 200); jt2.setSize(260, 200); jt1.setEditable(false); jt2.setEditable(false); jt1.setLineWrap(true); jt2.setLineWrap(true); jt1.setFont(new Font("楷体_GB2312", java.awt.Font.BOLD, 13)); jt1.setForeground(Color.blue); jt2.setFont(new Font("楷体_GB2312", java.awt.Font.BOLD, 13)); jt2.setForeground(Color.black); jPanel1.add(jt1); jPanel2.add(jt2); jTabbedPane.setSize(300, 200); jTabbedPane.addTab("游戏规则", null, jPanel1, null); jTabbedPane.addTab("声明", null, jPanel2, null); jMainPane.add(jTabbedPane); c.add(jMainPane); pack(); this.setVisible(true); }
// Конструктор класса public Log() { text = new JTextArea(); // Добавляем текст на панель text.setAlignmentX(LEFT_ALIGNMENT); // Позиционируем её налево text.setAlignmentY(TOP_ALIGNMENT); // и прижимаем к верху text.setBackground(Color.BLACK); // Задний фон - чёрный text.setForeground(Color.WHITE); // Цвет текста - белый text.setFont(References.LOG_FONT); // Стиль шрифта из файла References text.setLineWrap(true); // Устанавливаем перенос строк text.setWrapStyleWord(true); // И слов JScrollPane scrollPane = new JScrollPane(text); // Создаём ScrollBar scrollPane.setPreferredSize(new Dimension(500, 200)); // Ограничиваем размеры области вывода this.add(scrollPane); // Добавляем к нашей импровизированной консоли this.setVisible(true); // Отрисовываем }
AlertWindow(String message) { setTitle("Увага!"); setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); setSize(300, 200); setResizable(false); setLocation(100, 100); setVisible(true); setLayout(null); JPanel panel = new JPanel(new FlowLayout()); panel.setBounds(0, 40, 300, 40); panel.setBackground(MainColor); add(panel); JPanel panelForColor = new JPanel(null); panelForColor.setBounds(0, 0, 300, 40); panelForColor.setBackground(MainColor); add(panelForColor); JPanel ButtonPanel = new JPanel(new FlowLayout()); ButtonPanel.setBounds(0, 80, 300, 102); ButtonPanel.setBackground(MainColor); add(ButtonPanel); JButton OkButton = new JButton("Oк"); ButtonPanel.add(OkButton); JTextArea mainMessage = new JTextArea(message); mainMessage.setEditable(false); mainMessage.setForeground(Color.RED); mainMessage.setBackground(MainColor); panel.add(mainMessage); panel.updateUI(); OkButton.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent e) { dispose(); } }); }
public Credito() { super("Créditos"); final ImageIcon image = new ImageIcon("src/imagens/gato.gif"); // poe um novo simbolo no lugar do simbolo do java setIconImage(image.getImage()); // no frame abas = new JTabbedPane(); // instancia um objeto do tipo JTabbedPane JPanel jp = new JPanel( new GridLayout()); // seguinte aqui é a panel que vai ficar o conteudo ImageIcon img = new ImageIcon("src/imagens/batalhafundo.jpg"); JLabel label = new JLabel(img); jp.add(label, BorderLayout.CENTER); // coloca imagem no centro... // aqui eu adiciono a panel a JTabbedPane() a primeira aba (About) abas.setBackground(Color.RED); // o fundo da aba nao selecionada VERMELHA abas.addTab("About", jp); // o nome da aba sera (About) // adicionando a abas no frame principal getContentPane().add(abas); /** *************************************************************************************** */ // instanciando novamente para fazer referencia apenas ao conteudo da nova aba jp = new JPanel(new GridLayout()); // aqui eu adiciono a panel a JTabbedPane() a primeira aba (About) abas.setBackground(Color.RED); // o fundo da aba nao selecionada VERMELHA JOptionPane novo = new JOptionPane(); novo.showMessageDialog( null, "MAMP&R - Batalha Naval Versão 1.0\n" + "Edição de 32 bits\n" + "Copyright 2005-2007 MAMP&R\n" + "Todos os direitos reservados\n\n" + " © 2007 MAMP&R ", "Versão", JOptionPane.WARNING_MESSAGE, image); jp.add(novo); /** * ********************************************************************************************* */ // instanciando novamente para fazer referencia apenas ao conteudo da nova aba jp = new JPanel(new GridLayout()); JTextArea textArea; // cria uma variavel do tipo JTextArea textArea = new JTextArea(15, 20) { ImageIcon imagem = new ImageIcon("src/imagens/credito.jpg"); Image im = imagem.getImage(); // invoca uma figura para ficar como marca da agua public void paintComponent(Graphics g) { super.paintComponent(g); int x = (this.getWidth() - im.getWidth(null)) / 2; int y = (this.getHeight() - im.getHeight(null)) / 2; g.drawImage(im, x, y, this); } }; textArea.setLineWrap(true); // define a quebra de linha automática textArea.setWrapStyleWord(true); textArea.setEditable(false); // somente leitura textArea.setForeground(Color.RED); // cor do texto VERMELHA... JScrollPane scrollPane = new JScrollPane(textArea); // Define a fonte a ser usada Font fonte = new Font("Verdana", Font.BOLD, 13); textArea.setFont(fonte); jp.add(textArea); // add no Painel // cria uma aba chamada (CREDITO) abas.addTab("Credito", jp); this.getContentPane().add(abas); // add a ABA this.setVisible(true); // VISIVEL sim.. this.setSize(410, 400); // janela 400x 400 // ponhe no centro da tela... Dimension screen = Toolkit.getDefaultToolkit().getScreenSize(); this.setLocation( (screen.width - this.getSize().width) / 2, (screen.height - this.getSize().height) / 2); this.setResizable(false); // nao pode alterar o tamanho pre definido }
public LibGui() { // menu bar and menu item initialization menu = new JMenuBar(); m1 = new JMenu("Options"); m2 = new JMenu("Programs"); m3 = new JMenu("Help"); AddNew = new JMenuItem("AddNew"); Search = new JMenuItem("Search"); Display = new JMenuItem("Display"); Delete = new JMenuItem("Delete"); Modify = new JMenuItem("Modify"); Exit = new JMenuItem("Exit"); Help = new JMenuItem("Help"); // text area initialization tac = new JTextArea(2, 3); tac.setText("For: Birgang Institute of Technology" + " " + "Birganj,Parsa "); tac.setForeground(Color.red); tac.setEditable(false); // button intialization btnAddNew = new JButton("ADDNEW"); btnAddNew.setToolTipText("Add new Details"); btnSearch = new JButton("SEARCH"); btnSearch.setToolTipText("Search particular student"); btnDelete = new JButton("DELETE"); btnDelete.setToolTipText("Delete particular student"); btnDisplay = new JButton("DISPLAY"); btnDisplay.setToolTipText("Display particular student"); btnModify = new JButton("MODIFY"); btnModify.setToolTipText("Modifies particular student"); btnExit = new JButton("EXIT"); btnExit.setToolTipText("Out of Program"); // initialization panel pMain = new JPanel(); pNorth = new JPanel(); pSouth = new JPanel(); pCenter = new JPanel(); lbllogo = new JLabel(new ImageIcon("//G:/MFCfinish.gif"), JLabel.CENTER); // add menuitem to menu m1.add(AddNew); m1.add(Search); m1.add(Display); m1.add(Delete); m1.add(Modify); m2.add(Exit); m3.add(Help); menu.add(m1); menu.add(m2); menu.add(m3); pMain.add(btnAddNew); pMain.add(btnSearch); pMain.add(btnDelete); pMain.add(btnDisplay); pMain.add(btnModify); pMain.add(btnExit); pMain.setLayout(new BoxLayout(pMain, BoxLayout.Y_AXIS)); pMain.setBorder(BorderFactory.createTitledBorder("OPTIONS")); pMain.setLayout(new GridLayout(6, 1)); pMain.setBackground(Color.white); pCenter.setBackground(Color.red); pCenter.setLayout(new BoxLayout(pMain, BoxLayout.Y_AXIS)); pCenter.setLayout(new GridLayout(2, 1)); pCenter.add(lbllogo); pCenter.add(tac); pNorth.setBackground(Color.white); pNorth.add(menu); this.getContentPane().add(pMain, "West"); this.getContentPane().add(pCenter, "Center"); this.getContentPane().add(pNorth, "North"); this.setSize(400, 300); this.setResizable(false); this.setLocation(150, 150); this.setTitle("MENU"); this.show(); }
/** Updates all UI controls */ private void updatePreviewAndConflicts() { if (myButton == -1 || myModifiers == -1) { return; } myTarConflicts.setText(null); // Set text into preview area // empty string should have same height myLblPreview.setText( KeymapUtil.getMouseShortcutText(myButton, myModifiers, myRbSingleClick.isSelected() ? 1 : 2) + " "); // Detect conflicts final MouseShortcut mouseShortcut; if (myRbSingleClick.isSelected()) { mouseShortcut = new MouseShortcut(myButton, myModifiers, 1); } else { mouseShortcut = new MouseShortcut(myButton, myModifiers, 2); } StringBuilder buffer = new StringBuilder(); String[] actionIds = myKeymap.getActionIds(mouseShortcut); for (String actionId : actionIds) { if (actionId.equals(myActionId)) { continue; } String actionPath = myMainGroup.getActionQualifiedPath(actionId); // actionPath == null for editor actions having corresponding $-actions if (actionPath == null) { continue; } Shortcut[] shortcuts = myKeymap.getShortcuts(actionId); for (Shortcut shortcut1 : shortcuts) { if (!(shortcut1 instanceof MouseShortcut)) { continue; } MouseShortcut shortcut = (MouseShortcut) shortcut1; if (shortcut.getButton() != mouseShortcut.getButton() || shortcut.getModifiers() != mouseShortcut.getModifiers()) { continue; } if (buffer.length() > 1) { buffer.append('\n'); } buffer.append('['); buffer.append(actionPath); buffer.append(']'); break; } } if (buffer.length() == 0) { myTarConflicts.setForeground(UIUtil.getTextAreaForeground()); myTarConflicts.setText(KeyMapBundle.message("mouse.shortcut.dialog.no.conflicts.area")); } else { myTarConflicts.setForeground(Color.red); myTarConflicts.setText( KeyMapBundle.message("mouse.shortcut.dialog.assigned.to.area", buffer.toString())); } }
public void displayMessage(String message, boolean error) { if (error) messageLbl.setForeground(Color.red); else messageLbl.setForeground(UIManager.getColor("Label.foreground")); messageLbl.setText(message); }
private void initializeComponents() { this.setTitle("Synchro - Kopierassistent"); this.setBounds(0, 0, 550, 600); this.setResizable(true); this.setLayout(null); this.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE); this.addWindowListener(this); mainPanel = new JPanel(); mainPanel.setBounds(0, 0, this.getWidth() - 20, 25); // fcPanel.setBorder(BorderFactory.createLineBorder(Color.BLACK)); mainPanel.setLayout(null); btnBackup = new JButton("Backup"); btnBackup.setBounds(this.getWidth() / 2, 0, this.getWidth() / 2 - 20, mainPanel.getHeight()); btnBackup.addActionListener(this); mainPanel.add(btnBackup); this.add(mainPanel); fcPanel = new JPanel(); fcPanel.setBounds(10, 40, this.getWidth(), 260); // fcPanel.setBorder(BorderFactory.createLineBorder(Color.BLACK)); fcPanel.setLayout(null); quellLabel = new JLabel("Bitte Quellverzeichnis auswählen"); quellLabel.setBounds(10, 5, 320, 20); fcPanel.add(quellLabel); quellListModel = new DefaultListModel<>(); quellJList = new JList<ListItem>(quellListModel); quellJList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); quellJList.setLayoutOrientation(JList.VERTICAL); quellJList.addListSelectionListener(this); listBoxScroller = new JScrollPane(quellJList); listBoxScroller.setBounds(0, 30, 315, 100); fcPanel.add(listBoxScroller); btnQAuswahl = new JButton("Quellverz. hinzufügen"); btnQAuswahl.setBounds(320, 30, 200, 25); btnQAuswahl.addActionListener(this); fcPanel.add(btnQAuswahl); btnQEntfernen = new JButton("Quellverz. entfernen"); btnQEntfernen.setBounds(320, 60, 200, 25); btnQEntfernen.addActionListener(this); fcPanel.add(btnQEntfernen); zielLabel = new JLabel("Bitte Zielverzeichnis auswählen"); zielLabel.setBounds(10, 135, 320, 20); fcPanel.add(zielLabel); zielListModel = new DefaultListModel<>(); zielJList = new JList<ListItem>(zielListModel); zielJList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); zielJList.setLayoutOrientation(JList.VERTICAL); zielJList.addListSelectionListener(this); listBoxScroller2 = new JScrollPane(zielJList); listBoxScroller2.setBounds(0, 160, 315, 100); fcPanel.add(listBoxScroller2); btnZAuswahl = new JButton("Zielverz. hinzufügen"); btnZAuswahl.setBounds(320, 160, 200, 25); btnZAuswahl.addActionListener(this); fcPanel.add(btnZAuswahl); btnZEntfernen = new JButton("Zielverz. entfernen"); btnZEntfernen.setBounds(320, 190, 200, 25); btnZEntfernen.addActionListener(this); fcPanel.add(btnZEntfernen); this.add(fcPanel); ButtonGroup bGrp = new ButtonGroup(); optionPanel = new JPanel(); optionPanel.setBounds(10, 300 + 10, this.getWidth() - 40, 90); optionPanel.setPreferredSize(new Dimension(this.getWidth() - 40, 90)); // optionPanel.setBorder(BorderFactory.createLineBorder(Color.BLACK)); optionPanel.setLayout(new GridLayout(3, 1)); nUebSchr = new JRadioButton("Keine Dateien überschreiben"); nUebSchr.addItemListener(this); bGrp.add(nUebSchr); optionPanel.add(nUebSchr); ueSchr = new JRadioButton("Neuere Dateien überschreiben"); ueSchr.addItemListener(this); bGrp.add(ueSchr); optionPanel.add(ueSchr); aUeSchr = new JRadioButton("Alle Dateien überschreiben"); aUeSchr.addItemListener(this); bGrp.add(aUeSchr); optionPanel.add(aUeSchr); this.add(optionPanel); syncPanel = new JPanel(); syncPanel.setBounds( 10, optionPanel.getY() + optionPanel.getHeight() + 10, this.getWidth() - 30, 25); // syncPanel.setBorder(BorderFactory.createLineBorder(Color.BLACK)); syncPanel.setLayout(new BorderLayout()); btnSync = new JButton("Sync it!"); btnSync.setBounds(0, 0, 150, (syncPanel.getHeight() / 3)); btnSync.addActionListener(this); btnSync.setPreferredSize(new Dimension(150, (syncPanel.getHeight() / 3))); btnSync.setMaximumSize(new Dimension(150, (syncPanel.getHeight() / 3))); syncPanel.add(btnSync, BorderLayout.LINE_START); btnAbbruch = new JButton("Abbrechen"); btnAbbruch.setBounds(0, 0, 150, (syncPanel.getHeight() / 3)); btnAbbruch.addActionListener(this); btnAbbruch.setPreferredSize(new Dimension(150, (syncPanel.getHeight() / 3))); btnAbbruch.setMaximumSize(new Dimension(150, (syncPanel.getHeight() / 3))); btnAbbruch.setVisible(false); syncPanel.add(btnAbbruch, BorderLayout.LINE_END); progressBar = new JProgressBar(JProgressBar.HORIZONTAL); progressBar.setBorderPainted(true); progressBar.setPreferredSize(new Dimension(300, (syncPanel.getHeight() / 3))); progressBar.setForeground(Color.RED); progressBar.setStringPainted(true); progressBar.setVisible(true); syncPanel.add(progressBar, BorderLayout.CENTER); this.add(syncPanel); logPanel = new JPanel(); logPanel.setBounds( 10, syncPanel.getY() + syncPanel.getHeight() + 10, this.getWidth() - 30, 105); logPanel.setLayout(new BorderLayout()); textArea = new JTextArea(); textArea.setMargin(new Insets(3, 3, 3, 3)); textArea.setBackground(Color.black); textArea.setForeground(Color.LIGHT_GRAY); textArea.setAutoscrolls(true); textArea.setFocusable(false); textAreaScroller = new JScrollPane(textArea); DefaultCaret caret = (DefaultCaret) textArea.getCaret(); caret.setUpdatePolicy(DefaultCaret.ALWAYS_UPDATE); textAreaScroller.setBounds(0, 0, syncPanel.getWidth(), 50); logPanel.add(textAreaScroller, BorderLayout.CENTER); this.add(logPanel, BorderLayout.SOUTH); }
/* * 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; } }
/** Creates a file conversation component. */ public FileTransferConversationComponent() { imageLabel = new FileImageLabel(); constraints.gridx = 0; constraints.gridy = 0; constraints.gridwidth = 1; constraints.gridheight = 4; constraints.anchor = GridBagConstraints.NORTHWEST; constraints.insets = new Insets(5, 5, 5, 5); add(imageLabel, constraints); imageLabel.setIcon(new ImageIcon(ImageLoader.getImage(ImageLoader.DEFAULT_FILE_ICON))); constraints.gridx = 1; constraints.gridy = 0; constraints.gridwidth = 3; constraints.gridheight = 1; constraints.fill = GridBagConstraints.HORIZONTAL; constraints.weightx = 1.0; constraints.anchor = GridBagConstraints.NORTHWEST; constraints.insets = new Insets(5, 5, 5, 5); add(titleLabel, constraints); titleLabel.setFont(titleLabel.getFont().deriveFont(Font.BOLD, 11f)); constraints.gridx = 1; constraints.gridy = 1; constraints.anchor = GridBagConstraints.WEST; constraints.insets = new Insets(0, 5, 5, 5); add(fileLabel, constraints); constraints.gridx = 1; constraints.gridy = 2; constraints.gridwidth = 1; constraints.anchor = GridBagConstraints.WEST; constraints.insets = new Insets(0, 5, 0, 5); constraints.fill = GridBagConstraints.NONE; add(errorIconLabel, constraints); errorIconLabel.setVisible(false); constraints.gridx = 2; constraints.gridy = 2; constraints.gridwidth = 2; constraints.anchor = GridBagConstraints.WEST; constraints.insets = new Insets(0, 5, 0, 5); constraints.fill = GridBagConstraints.HORIZONTAL; add(errorArea, constraints); errorArea.setForeground(new Color(resources.getColor("service.gui.ERROR_FOREGROUND"))); setTextAreaStyle(errorArea); errorArea.setVisible(false); constraints.gridx = 1; constraints.gridy = 3; constraints.gridwidth = 1; constraints.gridheight = 1; constraints.weightx = 0.0; constraints.anchor = GridBagConstraints.WEST; constraints.insets = new Insets(0, 5, 0, 5); add(retryButton, constraints); retryButton.setText(GuiActivator.getResources().getI18NString("service.gui.RETRY")); retryButton.setVisible(false); constraints.gridx = 1; constraints.gridy = 3; constraints.gridwidth = 1; constraints.gridheight = 1; constraints.weightx = 0.0; constraints.anchor = GridBagConstraints.WEST; constraints.insets = new Insets(0, 5, 0, 5); add(cancelButton, constraints); cancelButton.setText(GuiActivator.getResources().getI18NString("service.gui.CANCEL")); cancelButton.addActionListener(this); cancelButton.setVisible(false); constraints.gridx = 2; constraints.gridy = 3; constraints.gridwidth = GridBagConstraints.RELATIVE; constraints.gridheight = 1; constraints.weightx = 0.0; constraints.fill = GridBagConstraints.NONE; constraints.anchor = GridBagConstraints.EAST; constraints.insets = new Insets(0, 5, 0, 5); constraints.gridx = 3; constraints.gridy = 3; constraints.gridwidth = 1; constraints.gridheight = 1; constraints.weightx = 0.0; constraints.fill = GridBagConstraints.NONE; constraints.anchor = GridBagConstraints.LINE_END; constraints.insets = new Insets(0, 5, 0, 5); add(progressPropertiesPanel, constraints); estimatedTimeLabel.setFont(estimatedTimeLabel.getFont().deriveFont(11f)); estimatedTimeLabel.setVisible(false); progressSpeedLabel.setFont(progressSpeedLabel.getFont().deriveFont(11f)); progressSpeedLabel.setVisible(false); progressPropertiesPanel.add(progressSpeedLabel); progressPropertiesPanel.add(estimatedTimeLabel); constraints.gridx = 1; constraints.gridy = 3; constraints.gridwidth = 1; constraints.gridheight = 1; constraints.weightx = 0.0; constraints.anchor = GridBagConstraints.WEST; constraints.insets = new Insets(0, 5, 0, 5); constraints.fill = GridBagConstraints.NONE; add(acceptButton, constraints); acceptButton.setText(GuiActivator.getResources().getI18NString("service.gui.ACCEPT")); acceptButton.setVisible(false); constraints.gridx = 2; constraints.gridy = 3; constraints.gridwidth = 1; constraints.gridheight = 1; constraints.weightx = 0.0; constraints.anchor = GridBagConstraints.WEST; constraints.insets = new Insets(0, 5, 0, 5); constraints.fill = GridBagConstraints.NONE; add(rejectButton, constraints); rejectButton.setText(GuiActivator.getResources().getI18NString("service.gui.REJECT")); rejectButton.setVisible(false); constraints.gridx = 1; constraints.gridy = 3; constraints.gridwidth = 1; constraints.gridheight = 1; constraints.weightx = 0.0; constraints.anchor = GridBagConstraints.WEST; constraints.insets = new Insets(0, 5, 0, 5); constraints.fill = GridBagConstraints.NONE; add(openFileButton, constraints); openFileButton.setText(GuiActivator.getResources().getI18NString("service.gui.OPEN")); openFileButton.setVisible(false); openFileButton.addActionListener(this); constraints.gridx = 2; constraints.gridy = 3; constraints.gridwidth = 1; constraints.gridheight = 1; constraints.weightx = 0.0; constraints.anchor = GridBagConstraints.WEST; constraints.insets = new Insets(0, 5, 0, 5); constraints.fill = GridBagConstraints.NONE; add(openFolderButton, constraints); openFolderButton.setText(GuiActivator.getResources().getI18NString("service.gui.OPEN_FOLDER")); openFolderButton.setVisible(false); openFolderButton.addActionListener(this); constraints.gridx = 1; constraints.gridy = 2; constraints.gridwidth = 3; constraints.gridheight = 1; constraints.weightx = 1.0; constraints.anchor = GridBagConstraints.WEST; constraints.insets = new Insets(0, 5, 0, 5); constraints.ipadx = 150; constraints.fill = GridBagConstraints.HORIZONTAL; add(progressBar, constraints); progressBar.setVisible(false); progressBar.setStringPainted(true); }
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; }
/** * The constructor creates the NodeTable and DirectedGraph taken the information from files * lines-gbg.txt and stops-gbg.txt and makes itself visible. */ public ShortRoute(String file) { // try to convert to UTF-8 across plattforms to make Swedish chars work // System.out.println("charset = " + java.nio.charset.Charset.defaultCharset()); // MacRoman macintosh Windows-1252 ISO 8859-1 UTF-8 try { // convert whatever this file is encoded in to UTF-8, // kill the exception (can't happen) introText = new String( introText.getBytes(java.nio.charset.Charset.defaultCharset().toString()), "UTF-8"); felTextStart = new String( felTextStart.getBytes(java.nio.charset.Charset.defaultCharset().toString()), "UTF-8"); felTextSlut = new String( felTextSlut.getBytes(java.nio.charset.Charset.defaultCharset().toString()), "UTF-8"); frome = new String(frome.getBytes(java.nio.charset.Charset.defaultCharset().toString()), "UTF-8"); } catch (UnsupportedEncodingException e) { System.exit(0); } // read the graph and draw it in a separate window // creates the graph and fills the p-queue "names" karta.setLocation(50, 250); if (file == null) { readAndDrawGraph(); } else { readAndDrawBIGGraph(file); } System.out.println("Version with sorting fixed"); // debug // now to the graphics in the Frame // Left part // select is a panel for structuring the left part // i.e label, textfield for "from", label, textfield for "to" JPanel select = new JPanel(new GridLayout(4, 1)); select.setBackground(Color.yellow); select.add(new JLabel("Ange startpunkt !", JLabel.CENTER)); select.add(from); select.add(new JLabel("Ange slutpunkt !", JLabel.CENTER)); select.add(to); from.setBackground(Color.white); from.setForeground(Color.blue); to.setBackground(Color.white); to.setForeground(Color.blue); from.addActionListener(this); to.addActionListener(this); // Middle part // route is the middle text area part where messages are displayed // give the middle text area a scrollbar to the right route = new JTextArea(introText, 12, 40); route.setEditable(false); JScrollPane routeScrollPane = new JScrollPane(route); routeScrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER); route.setBackground(Color.white); route.setForeground(Color.blue); // Rigth part JLabel head = new JLabel(" **** Alternativ ***** "); head.setForeground(Color.red); // add all stations to the right scrollpane // tanken är att dom skall vara valbara men det fungerar inte än // En JList vill ha en ListModel som parameter // En ListModel är ett interface som implementeras av klassen AbstractListModel // DefaultListModel ärver AbstractListModel DefaultListModel<String> valList = new DefaultListModel<String>(); JList<String> alternativ = new JList<String>(valList); alternativ.setBackground(Color.white); alternativ.setForeground(Color.blue); // add a scroll pane to the station list in alternativ stationList = new JScrollPane(alternativ); // read names from p-queue and load them into the list while (!names.isEmpty()) valList.addElement(names.poll()); // panel for structure JPanel valPanel = new JPanel(new BorderLayout()); valPanel.setBackground(Color.white); valPanel.add(head, "North"); valPanel.add(stationList, "Center"); // put it all together in the frame add(select, "West"); add(routeScrollPane, "Center"); add(valPanel, "East"); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); pack(); setVisible(true); } // end ShortRoute
public static void ConfigureMainWindow() { userNameLabel.setFont(new Font("Lucida Console", 0, 14)); userNameLabel.setForeground(new Color(255, 255, 255)); mainWindow.getContentPane().setBackground(new Color(4, 3, 10)); mainWindow.setSize(800, 600); mainWindow.getContentPane().setLayout(null); connectButton.setBackground(new Color(255, 255, 255)); connectButton.setForeground(new Color(4, 3, 10)); connectButton.setFont(new Font("Lucida Console", 0, 14)); connectButton.setText("Anslut"); connectButton.setToolTipText(""); mainWindow.getContentPane().add(connectButton); connectButton.setBounds(455, 10, 100, 25); conversation.setColumns(20); conversation.setFont(new Font("Lucida Console", 0, 14)); conversation.setForeground(new Color(4, 3, 10)); conversation.setLineWrap(true); conversation.setRows(5); // conversation.setEditable(false); tpConversation.setForeground(new Color(255, 255, 255)); tpConversation.setBounds(10, 10, 600, 500); tpConversation.setBackground(new Color(4, 3, 10)); tpConversation.setFont(new Font("Lucida Console", 0, 14)); spConversation.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER); spConversation.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS); spConversation.setViewportView(tpConversation); mainWindow.getContentPane().add(spConversation); spConversation.setBounds(10, 10, 600, 500); userNameBox.setBounds(120, 10, 325, 25); userNameLabel.setBounds(10, 10, 130, 25); mainWindow.getContentPane().add(userNameBox); mainWindow.getContentPane().add(userNameLabel); usersOnline.setForeground(new Color(0, 180, 255)); usersOnline.setBackground(new Color(4, 3, 10)); usersOnline.setFont(new Font("Lucida Console", 0, 14)); spUsersOnline.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER); spUsersOnline.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS); spUsersOnline.setViewportView(usersOnline); mainWindow.getContentPane().add(spUsersOnline); spUsersOnline.setBounds(620, 10, 165, 300); messageField.setForeground(new Color(255, 255, 255)); messageField.setBackground(new Color(4, 3, 10)); messageField.requestFocus(); messageField.addActionListener(action); mainWindow.getContentPane().add(messageField); messageField.setBounds(10, 520, 600, 30); send.setBackground(new Color(255, 255, 255)); send.setForeground(new Color(4, 3, 10)); send.setText("Skicka"); send.setFont(new Font("Lucida Console", 0, 14)); mainWindow.getContentPane().add(send); send.setBounds(620, 520, 165, 30); disconnect.setBackground(new Color(255, 255, 255)); disconnect.setForeground(new Color(4, 3, 10)); disconnect.setText("Avsluta chatten"); disconnect.setFont(new Font("Lucida Console", 0, 14)); mainWindow.getContentPane().add(disconnect); disconnect.setBounds(620, 320, 165, 30); error.setFont(new Font("Lucida Console", 0, 14)); error.setForeground(new Color(255, 0, 23)); error.setBounds(120, 40, 525, 25); mainWindow.getContentPane().add(error); }
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)); }
/** 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); } }; }