private void addInformationPanel() { // Create UI elements for connection information. JPanel informationPanel = new JPanel(); informationPanel.setLayout(new BorderLayout()); // Add the Host information JPanel connPanel = new JPanel(); connPanel.setLayout(new GridBagLayout()); connPanel.setBorder(BorderFactory.createTitledBorder("Connection information")); JLabel label = new JLabel("Host: "); label.setMinimumSize(new java.awt.Dimension(150, 14)); label.setMaximumSize(new java.awt.Dimension(150, 14)); connPanel.add( label, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0, 21, 0, new Insets(0, 0, 0, 0), 0, 0)); JFormattedTextField field = new JFormattedTextField(connection.getServiceName()); field.setMinimumSize(new java.awt.Dimension(150, 20)); field.setMaximumSize(new java.awt.Dimension(150, 20)); field.setEditable(false); field.setBorder(null); connPanel.add( field, new GridBagConstraints(1, 0, 1, 1, 1.0, 0.0, 10, 2, new Insets(0, 0, 0, 0), 0, 0)); // Add the Port information label = new JLabel("Port: "); label.setMinimumSize(new java.awt.Dimension(150, 14)); label.setMaximumSize(new java.awt.Dimension(150, 14)); connPanel.add( label, new GridBagConstraints(0, 1, 1, 1, 0.0, 0.0, 21, 0, new Insets(0, 0, 0, 0), 0, 0)); field = new JFormattedTextField(connection.getPort()); field.setMinimumSize(new java.awt.Dimension(150, 20)); field.setMaximumSize(new java.awt.Dimension(150, 20)); field.setEditable(false); field.setBorder(null); connPanel.add( field, new GridBagConstraints(1, 1, 1, 1, 0.0, 0.0, 10, 2, new Insets(0, 0, 0, 0), 0, 0)); // Add the connection's User information label = new JLabel("User: "******"Creation time: "); label.setMinimumSize(new java.awt.Dimension(150, 14)); label.setMaximumSize(new java.awt.Dimension(150, 14)); connPanel.add( label, new GridBagConstraints(0, 3, 1, 1, 0.0, 0.0, 21, 0, new Insets(0, 0, 0, 0), 0, 0)); field = new JFormattedTextField(new SimpleDateFormat("yyyy.MM.dd hh:mm:ss:SS aaa")); field.setMinimumSize(new java.awt.Dimension(150, 20)); field.setMaximumSize(new java.awt.Dimension(150, 20)); field.setValue(creationTime); field.setEditable(false); field.setBorder(null); connPanel.add( field, new GridBagConstraints(1, 3, 1, 1, 0.0, 0.0, 10, 2, new Insets(0, 0, 0, 0), 0, 0)); // Add the connection's creationTime information label = new JLabel("Status: "); label.setMinimumSize(new java.awt.Dimension(150, 14)); label.setMaximumSize(new java.awt.Dimension(150, 14)); connPanel.add( label, new GridBagConstraints(0, 4, 1, 1, 0.0, 0.0, 21, 0, new Insets(0, 0, 0, 0), 0, 0)); statusField = new JFormattedTextField(); statusField.setMinimumSize(new java.awt.Dimension(150, 20)); statusField.setMaximumSize(new java.awt.Dimension(150, 20)); statusField.setValue("Active"); statusField.setEditable(false); statusField.setBorder(null); connPanel.add( statusField, new GridBagConstraints(1, 4, 1, 1, 0.0, 0.0, 10, 2, new Insets(0, 0, 0, 0), 0, 0)); // Add the connection panel to the information panel informationPanel.add(connPanel, BorderLayout.NORTH); // Add the Number of sent packets information JPanel packetsPanel = new JPanel(); packetsPanel.setLayout(new GridLayout(1, 1)); packetsPanel.setBorder(BorderFactory.createTitledBorder("Transmitted Packets")); statisticsTable = new DefaultTableModel( new Object[][] { {"IQ", 0, 0}, {"Message", 0, 0}, {"Presence", 0, 0}, {"Other", 0, 0}, {"Total", 0, 0} }, new Object[] {"Type", "Received", "Sent"}) { private static final long serialVersionUID = -6793886085109589269L; public boolean isCellEditable(int rowIndex, int mColIndex) { return false; } }; JTable table = new JTable(statisticsTable); // Allow only single a selection table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); packetsPanel.add(new JScrollPane(table)); // Add the packets panel to the information panel informationPanel.add(packetsPanel, BorderLayout.CENTER); tabbedPane.add("Information", new JScrollPane(informationPanel)); tabbedPane.setToolTipTextAt(4, "Information and statistics about the debugged connection"); }
@Override public void installUI(JComponent c) { super.installUI(c); textFormattedField = (JFormattedTextField) c; textFormattedField.setFocusable(true); textFormattedField.setOpaque(false); textFormattedField.setMargin(new Insets(0, 0, 0, 0)); textFormattedField.setBorder(BorderFactory.createEmptyBorder(4, 4, 4, 4)); textFormattedField.setFont(AdobeLookAndFeel.fontBold); textFormattedField.setForeground(AdobeLookAndFeel.colorText); textFormattedField.setSelectionColor(new Color(100, 100, 100)); textFormattedField.setCaretColor(AdobeLookAndFeel.colorText); mouseAdapter = new MouseAdapter() { @Override public void mouseReleased(MouseEvent e) { textFormattedField.repaint(); } @Override public void mousePressed(MouseEvent e) { textFormattedField.repaint(); } @Override public void mouseClicked(MouseEvent e) { textFormattedField.repaint(); } }; textFormattedField.addMouseListener(mouseAdapter); keyAdapter = new KeyAdapter() { @Override public void keyPressed(KeyEvent e) { textFormattedField.repaint(); } }; textFormattedField.addKeyListener(keyAdapter); focusListener = new FocusAdapter() { @Override public void focusGained(FocusEvent e) { textFormattedField.repaint(); } @Override public void focusLost(FocusEvent e) { textFormattedField.repaint(); } }; textFormattedField.addFocusListener(focusListener); propertyChangeListener = new PropertyChangeListener() { @Override public void propertyChange(PropertyChangeEvent evt) { textFormattedField.repaint(); } }; textFormattedField.addPropertyChangeListener( AccessibleContext.ACCESSIBLE_STATE_PROPERTY, propertyChangeListener); }
/** * @param tf * @param format */ public TableCellEditorForDezimal(final JFormattedTextField tf, final NumberFormat format) { super(tf); super.setClickCountToStart(1); tf.setFocusLostBehavior(JFormattedTextField.COMMIT); tf.setHorizontalAlignment(SwingConstants.LEFT); tf.setBorder(null); delegate = new EditorDelegate() { boolean isMousePressed = false; @Override public void setValue(Object param) { if (isMousePressed && param != null && (param.getClass() == Double.class || param.getClass() == BigDecimal.class)) { SwingUtilities.invokeLater( new Runnable() { public void run() { tf.selectAll(); } }); try { tf.setText( format == null ? FormatNumber.formatDezimal((Number) param) : format.format((Number) param)); } catch (Exception e) { try { param = new BigDecimal(String.valueOf(param)); tf.setText( format == null ? FormatNumber.formatDezimal((Number) param) : format.format((Number) param)); } catch (Exception ex) { tf.setText(String.valueOf(param)); } } } else { tf.setText(""); } } @Override public Object getCellEditorValue() { try { String _field = tf.getText(); Number _number = (format == null ? FormatNumber.parseDezimal(_field) : format.parse(_field)); if (_number != null) { double _parsed = _number.doubleValue(); BigDecimal d = BigDecimal.valueOf(_parsed); // tf.setBackground(Color.white); return d; } else { // tf.setBackground(Color.white); return BigDecimal.ZERO; } } catch (ParseException e) { Log.Debug(this, e); // tf.setBackground(Color.red); return BigDecimal.ZERO; } } @Override public boolean isCellEditable(EventObject anEvent) { if (anEvent instanceof MouseEvent) { isMousePressed = true; return ((MouseEvent) anEvent).getClickCount() >= clickCountToStart; } isMousePressed = false; return true; } }; }
public DefaultDnDSupport() { JFrame fen = new JFrame("DnD et CCP"); fen.getContentPane().setLayout(new FlowLayout(FlowLayout.CENTER)); fen.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // Panel gauche JPanel panelgauche = new JPanel(); panelgauche.setLayout(new BoxLayout(panelgauche, BoxLayout.Y_AXIS)); // JTextField JTextField textField = new JTextField(10); textField.setBorder( BorderFactory.createCompoundBorder( BorderFactory.createTitledBorder("JTextField"), BorderFactory.createEmptyBorder(5, 5, 5, 5))); textField.setDragEnabled(true); // JPasswordField JPasswordField passwordField = new JPasswordField(10); passwordField.setBorder( BorderFactory.createCompoundBorder( BorderFactory.createTitledBorder("JPasswordField"), BorderFactory.createEmptyBorder(5, 5, 5, 5))); passwordField.setDragEnabled(true); // JFormattedTextField JFormattedTextField ftf = new JFormattedTextField("Universite de Lille 1"); ftf.setFont(new Font("Courier", Font.ITALIC, 12)); ftf.setBorder( BorderFactory.createCompoundBorder( BorderFactory.createTitledBorder("JFormattedTextField"), BorderFactory.createEmptyBorder(5, 5, 5, 5))); ftf.setDragEnabled(true); // JTextArea JTextArea jta = new JTextArea("Master 1 informatique"); jta.setFont(new Font("Arial", Font.BOLD, 12)); jta.setBorder( BorderFactory.createCompoundBorder( BorderFactory.createTitledBorder("JTextArea"), BorderFactory.createEmptyBorder(5, 5, 5, 5))); jta.setDragEnabled(true); // JEditorPane JEditorPane editorPane = createEditorPane(); editorPane.setDragEnabled(true); JScrollPane editorScrollPane = new JScrollPane(editorPane); editorScrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS); editorScrollPane.setBorder( BorderFactory.createCompoundBorder( BorderFactory.createTitledBorder("JEditorPane"), BorderFactory.createEmptyBorder(5, 5, 5, 5))); // JColorChooser JColorChooser cc = new JColorChooser(); cc.setDragEnabled(true); cc.setBorder( BorderFactory.createCompoundBorder( BorderFactory.createTitledBorder("JColorChooser"), BorderFactory.createEmptyBorder(5, 5, 5, 5))); // Panel droit JPanel paneldroit = new JPanel(); paneldroit.setLayout(new BoxLayout(paneldroit, BoxLayout.Y_AXIS)); // JList String[] data = { "AAC", "AEV", "ANG", "ASE", "COA", "PJE", "CAR", "PJI", "AeA", "BDA", "CALP", "FDD", "HECI", "IHM", "M3DS", "PAC", "PPD", "RdF", "SVL", "TI" }; JList liste = new JList(data); JScrollPane jscrollListe = new JScrollPane(liste); jscrollListe.setBorder( BorderFactory.createCompoundBorder( BorderFactory.createTitledBorder("JList"), BorderFactory.createEmptyBorder(5, 5, 5, 5))); // liste.setDragEnabled(true); // JTree DefaultMutableTreeNode m1 = new DefaultMutableTreeNode("M1"); DefaultMutableTreeNode s1 = new DefaultMutableTreeNode("S1"); m1.add(s1); s1.add(new DefaultMutableTreeNode("AAC")); s1.add(new DefaultMutableTreeNode("AEV")); s1.add(new DefaultMutableTreeNode("ANG")); s1.add(new DefaultMutableTreeNode("ASE")); s1.add(new DefaultMutableTreeNode("COA")); s1.add(new DefaultMutableTreeNode("PJE")); DefaultMutableTreeNode s2 = new DefaultMutableTreeNode("S2"); m1.add(s2); s2.add(new DefaultMutableTreeNode("CAR")); s2.add(new DefaultMutableTreeNode("PJI")); s2.add(new DefaultMutableTreeNode("AeA")); s2.add(new DefaultMutableTreeNode("BDA")); s2.add(new DefaultMutableTreeNode("CALP")); s2.add(new DefaultMutableTreeNode("FDD")); s2.add(new DefaultMutableTreeNode("HECI")); s2.add(new DefaultMutableTreeNode("IHM")); s2.add(new DefaultMutableTreeNode("M3DS")); s2.add(new DefaultMutableTreeNode("PAC")); s2.add(new DefaultMutableTreeNode("PPD")); s2.add(new DefaultMutableTreeNode("RdF")); s2.add(new DefaultMutableTreeNode("SVL")); s2.add(new DefaultMutableTreeNode("TI")); JTree tree = new JTree(m1); // tree.setDragEnabled(true); JScrollPane jscrollTree = new JScrollPane(tree); jscrollTree.setBorder( BorderFactory.createCompoundBorder( BorderFactory.createTitledBorder("JTree"), BorderFactory.createEmptyBorder(5, 5, 5, 5))); jscrollTree.setPreferredSize(new Dimension(200, 200)); // JTable String[] columnNames = {"S1", "S2"}; Object[][] data2 = { {"AAC", "CAR"}, {"AEV", "PJI"}, {"ANG", "AeA"}, {"ASE", "BDA"}, {"COA", "CALP"}, {"PJE", "FDD"}, {"", "HECI"}, {"", "IHM"}, {"", "M3DS"}, {"", "PAC"}, {"", "PPD"}, {"", "RdF"}, {"", "SVL"}, {"", "TI"} }; JTable table = new JTable(data2, columnNames); JScrollPane scrollPaneTable = new JScrollPane(table); table.setDragEnabled(true); // JFileChooser JFileChooser fc = new JFileChooser(); fc.setBorder( BorderFactory.createCompoundBorder( BorderFactory.createTitledBorder("JFileChooser"), BorderFactory.createEmptyBorder(5, 5, 5, 5))); fc.setDragEnabled(true); panelgauche.add(textField); panelgauche.add(passwordField); panelgauche.add(ftf); panelgauche.add(jta); panelgauche.add(cc); panelgauche.add(editorScrollPane); fen.getContentPane().add(panelgauche); paneldroit.add(fc); paneldroit.add(jscrollListe); paneldroit.add(jscrollTree); paneldroit.add(scrollPaneTable); fen.getContentPane().add(paneldroit); fen.pack(); fen.setVisible(true); }