/** Listener to handle button actions */ public void actionPerformed(ActionEvent e) { // Check if the user pressed the remove button if (e.getSource() == remove_button) { int row = table.getSelectedRow(); model.removeRow(row); table.clearSelection(); table.repaint(); valueChanged(null); } // Check if the user pressed the remove all button if (e.getSource() == remove_all_button) { model.clearAll(); table.setRowSelectionInterval(0, 0); table.repaint(); valueChanged(null); } // Check if the user pressed the filter button if (e.getSource() == filter_button) { filter.showDialog(); if (filter.okPressed()) { // Update the display with new filter model.setFilter(filter); table.repaint(); } } // Check if the user pressed the start button if (e.getSource() == start_button) { start(); } // Check if the user pressed the stop button if (e.getSource() == stop_button) { stop(); } // Check if the user wants to switch layout if (e.getSource() == layout_button) { details_panel.remove(details_soap); details_soap.removeAll(); if (details_soap.getOrientation() == JSplitPane.HORIZONTAL_SPLIT) { details_soap = new JSplitPane(JSplitPane.VERTICAL_SPLIT); } else { details_soap = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT); } details_soap.setTopComponent(request_panel); details_soap.setRightComponent(response_panel); details_soap.setResizeWeight(.5); details_panel.add(details_soap, BorderLayout.CENTER); details_panel.validate(); details_panel.repaint(); } // Check if the user is changing the reflow option if (e.getSource() == reflow_xml) { request_text.setReflowXML(reflow_xml.isSelected()); response_text.setReflowXML(reflow_xml.isSelected()); } }
public void setCurrentLayout(int newId) { if (newId >= nviews) return; tabbedPane.removeAll(); tabbedToolPanel.removeAll(); String key; String currValue; JComponent obj; PushpinIF pobj; clearPushpinComp(); for (int i = 0; i < keys.size(); i++) { key = (String) keys.get(i); currValue = (String) tp_paneInfo[newId].get(key); obj = (JComponent) panes.get(key); pobj = null; if (currValue.equals("yes") && obj != null) { if (obj instanceof PushpinIF) { pobj = (PushpinIF) obj; pobj.setAvailable(true); if (!pobj.isOpen()) { if (!pobj.isPopup()) obj = null; } } if (obj != null) { if (key.equals("Locator")) key = getLocatorName(); tabbedPane.addTab(key, null, obj, ""); } // tabbedPane.addTab(key, null, (JComponent)panes.get(key), ""); } } if (tabbedPane.getTabCount() < 1) { pinPanel.setAvailable(false); pinPanel.setStatus("close"); // setVisible(false); return; } pinPanel.setAvailable(true); pinPanel.setStatus("open"); if (tabbedPane.getTabCount() == 1) { tabbedToolPanel.add(tabbedPane.getComponentAt(0)); // tabbedToolPanel.add(tabbedPane); } else { tabbedToolPanel.add(tabbedPane); } setSelectedTab(tp_selectedTab, selectedTabName); tabbedToolPanel.validate(); // repaint(); }
public void setCommands(String[] names) { panel.removeAll(); panel.add(Box.createHorizontalGlue()); for (int i = 0; i < names.length; i++) { JButton b = new XButton(""); if (shownames) b.setText(names[i]); else b.setToolTipText(names[i]); b.setActionCommand(names[i]); b.addActionListener(this); b.setMargin(new InsetsUIResource(0, 6, 0, 6)); panel.add(b); if (i < names.length - 1) { if (isHorisontal()) { panel.add(Box.createHorizontalStrut(9)); } else { panel.add(Box.createVerticalStrut(5)); } } buttons.put(names[i], b); } setButtonsSize(); panel.validate(); }
public void setFrame() { f = new JFrame("数据通讯参数设置"); // 获取屏幕分辨率的工具集 Toolkit tool = Toolkit.getDefaultToolkit(); // 利用工具集获取屏幕的分辨率 Dimension dim = tool.getScreenSize(); // 获取屏幕分辨率的高度 int height = (int) dim.getHeight(); // 获取屏幕分辨率的宽度 int width = (int) dim.getWidth(); // 设置位置 f.setLocation((width - 300) / 2, (height - 400) / 2); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.pack(); f.setVisible(true); f.setContentPane(this); f.setSize(320, 260); f.setResizable(false); lblIP = new JLabel("主机名"); txtIp = new JTextField(20); try { InetAddress addr = InetAddress.getLocalHost(); txtIp.setText(addr.getHostAddress().toString()); } catch (Exception ex) { } lblNo = new JLabel("端口号"); cmbNo = new JComboBox(); cmbNo.setEditable(true); cmbNo.addPopupMenuListener( new PopupMenuListener() { @Override public void popupMenuWillBecomeVisible(PopupMenuEvent e) { cmbNo.removeAllItems(); CommPortIdentifier portId = null; Enumeration portList; portList = CommPortIdentifier.getPortIdentifiers(); while (portList.hasMoreElements()) { portId = (CommPortIdentifier) portList.nextElement(); cmbNo.addItem(portId.getName()); } } @Override public void popupMenuWillBecomeInvisible(PopupMenuEvent e) { // To change body of implemented methods use File | Settings | File Templates. } @Override public void popupMenuCanceled(PopupMenuEvent e) { // To change body of implemented methods use File | Settings | File Templates. } }); lblName = new JLabel("工程名"); txtProjectName = new JComboBox(); txtProjectName.setEditable(true); txtProjectName.addPopupMenuListener( new PopupMenuListener() { @Override public void popupMenuWillBecomeVisible(PopupMenuEvent e) { txtProjectName.removeAllItems(); Mongo m1 = null; try { m1 = new Mongo(txtIp.getText().toString(), 27017); } catch (UnknownHostException ex) { ex.printStackTrace(); } for (String name : m1.getDatabaseNames()) { txtProjectName.addItem(name); } m1.close(); } @Override public void popupMenuWillBecomeInvisible(PopupMenuEvent e) { // To change body of implemented methods use File | Settings | File Templates. } @Override public void popupMenuCanceled(PopupMenuEvent e) { // To change body of implemented methods use File | Settings | File Templates. } }); lblBote = new JLabel("波特率"); cmbBote = new JComboBox(); cmbBote.addItem(9600); cmbBote.addItem(19200); cmbBote.addItem(57600); cmbBote.addItem(115200); lblLength = new JLabel("数据长度"); cmbLength = new JComboBox(); cmbLength.addItem(8); cmbLength.addItem(7); lblParity = new JLabel("校验"); cmbParity = new JComboBox(); cmbParity.addItem("None"); cmbParity.addItem("Odd"); cmbParity.addItem("Even"); lblStopBit = new JLabel("停止位"); cmbStopBit = new JComboBox(); cmbStopBit.addItem(1); cmbStopBit.addItem(2); lblDelay = new JLabel("刷新"); txtDelay = new JTextField(20); btnOk = new JButton("确定"); btnOk.addActionListener( new AbstractAction() { @Override public void actionPerformed(ActionEvent e) { paramIp = txtIp.getText().toString(); paramName = txtProjectName.getSelectedItem().toString(); paramNo = cmbNo.getSelectedItem().toString(); paramBote = Integer.parseInt(cmbBote.getSelectedItem().toString()); parmLength = Integer.parseInt(cmbLength.getSelectedItem().toString()); parmParity = cmbParity.getSelectedIndex(); parmStopBit = Integer.parseInt(cmbStopBit.getSelectedItem().toString()); parmDelay = Integer.parseInt(txtDelay.getText().toString()); if (!paramName.equals("") && !paramNo.equals("")) { receiveData( paramIp, paramName, paramNo, paramBote, parmLength, parmParity, parmStopBit, parmDelay); } else { } } }); btnCancel = new JButton("取消"); btnCancel.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent e) { System.exit(0); } }); JPanel p1 = new JPanel(); p1.setLayout(new GridLayout(9, 2)); p1.add(lblIP); p1.add(txtIp); p1.add(lblNo); p1.add(cmbNo); p1.add(lblName); p1.add(txtProjectName); p1.add(lblBote); p1.add(cmbBote); p1.add(lblLength); p1.add(cmbLength); p1.add(lblParity); p1.add(cmbParity); p1.add(lblStopBit); p1.add(cmbStopBit); p1.add(lblDelay); p1.add(txtDelay); txtDelay.setText("500"); p1.add(btnOk); p1.add(btnCancel); p1.validate(); f.add(p1); f.validate(); }
protected void buildErrorPanel() { errorPanel = new JPanel(); GroupLayout layout = new GroupLayout(errorPanel); layout.setAutoCreateGaps(true); layout.setAutoCreateContainerGaps(true); errorPanel.setLayout(layout); // errorPanel.setBorder(BorderFactory.createMatteBorder(2, 0, 0, 0, Color.BLACK)); errorMessage = new JTextPane(); errorMessage.setEditable(false); errorMessage.setContentType("text/html"); errorMessage.setText( "<html><body>Could not connect to the Processing server.<br>" + "Contributions cannot be installed or updated without an Internet connection.<br>" + "Please verify your network connection again, then try connecting again.</body></html>"); errorMessage.setFont(Toolkit.getSansFont(14, Font.PLAIN)); errorMessage.setMaximumSize(new Dimension(550, 50)); errorMessage.setOpaque(false); StyledDocument doc = errorMessage.getStyledDocument(); SimpleAttributeSet center = new SimpleAttributeSet(); StyleConstants.setAlignment(center, StyleConstants.ALIGN_CENTER); doc.setParagraphAttributes(0, doc.getLength(), center, false); closeButton = new JButton("X"); closeButton.setContentAreaFilled(false); closeButton.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { contribDialog.makeAndShowTab(false, false); } }); tryAgainButton = new JButton("Try Again"); tryAgainButton.setFont(Toolkit.getSansFont(14, Font.PLAIN)); tryAgainButton.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { contribDialog.makeAndShowTab(false, true); contribDialog.downloadAndUpdateContributionListing(editor.getBase()); } }); layout.setHorizontalGroup( layout .createSequentialGroup() .addPreferredGap( LayoutStyle.ComponentPlacement.RELATED, GroupLayout.PREFERRED_SIZE, Short.MAX_VALUE) .addGroup( layout .createParallelGroup(GroupLayout.Alignment.CENTER) .addComponent(errorMessage) .addComponent( tryAgainButton, StatusPanel.BUTTON_WIDTH, StatusPanel.BUTTON_WIDTH, StatusPanel.BUTTON_WIDTH)) .addPreferredGap( LayoutStyle.ComponentPlacement.RELATED, GroupLayout.PREFERRED_SIZE, Short.MAX_VALUE) .addComponent(closeButton)); layout.setVerticalGroup( layout .createSequentialGroup() .addGroup( layout.createParallelGroup().addComponent(errorMessage).addComponent(closeButton)) .addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED) .addComponent(tryAgainButton)); errorPanel.setBackground(Color.PINK); errorPanel.validate(); }
/** * This adds the specified component to the setup panel. It is added below the last 'default' * item. You can only add 1 component here, so if you need to add multiple things, you'll have to * handle adding that to yourself to the one component. * * @param component the component to add. */ public void setCustomPanel(JComponent component) { customPanelPlaceHolder.add(component, BorderLayout.CENTER); customPanelPlaceHolder.invalidate(); mainPanel.validate(); }