List of usage examples for javax.swing JPanel getLayout
public LayoutManager getLayout()
From source file:Main.java
/** Resize the panel correctly, based on size of things in it. We're assuming that sqlEdit has been added to the panel as well. */ public static void resizeJPanel(JPanel p) { Dimension d = p.getLayout().preferredLayoutSize(p); p.setPreferredSize(d);/*from w w w . j a v a2 s . co m*/ }
From source file:DesktopAppTest.java
public DesktopAppFrame() { setLayout(new GridBagLayout()); final JFileChooser chooser = new JFileChooser(); JButton fileChooserButton = new JButton("..."); final JTextField fileField = new JTextField(20); fileField.setEditable(false);/* w w w . j a v a2 s . c o m*/ JButton openButton = new JButton("Open"); JButton editButton = new JButton("Edit"); JButton printButton = new JButton("Print"); final JTextField browseField = new JTextField(); JButton browseButton = new JButton("Browse"); final JTextField toField = new JTextField(); final JTextField subjectField = new JTextField(); JButton mailButton = new JButton("Mail"); openButton.setEnabled(false); editButton.setEnabled(false); printButton.setEnabled(false); browseButton.setEnabled(false); mailButton.setEnabled(false); if (Desktop.isDesktopSupported()) { Desktop desktop = Desktop.getDesktop(); if (desktop.isSupported(Desktop.Action.OPEN)) openButton.setEnabled(true); if (desktop.isSupported(Desktop.Action.EDIT)) editButton.setEnabled(true); if (desktop.isSupported(Desktop.Action.PRINT)) printButton.setEnabled(true); if (desktop.isSupported(Desktop.Action.BROWSE)) browseButton.setEnabled(true); if (desktop.isSupported(Desktop.Action.MAIL)) mailButton.setEnabled(true); } fileChooserButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { if (chooser.showOpenDialog(DesktopAppFrame.this) == JFileChooser.APPROVE_OPTION) fileField.setText(chooser.getSelectedFile().getAbsolutePath()); } }); openButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { try { Desktop.getDesktop().open(chooser.getSelectedFile()); } catch (IOException ex) { ex.printStackTrace(); } } }); editButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { try { Desktop.getDesktop().edit(chooser.getSelectedFile()); } catch (IOException ex) { ex.printStackTrace(); } } }); printButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { try { Desktop.getDesktop().print(chooser.getSelectedFile()); } catch (IOException ex) { ex.printStackTrace(); } } }); browseButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { try { Desktop.getDesktop().browse(new URI(browseField.getText())); } catch (URISyntaxException ex) { ex.printStackTrace(); } catch (IOException ex) { ex.printStackTrace(); } } }); mailButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { try { String subject = percentEncode(subjectField.getText()); URI uri = new URI("mailto:" + toField.getText() + "?subject=" + subject); System.out.println(uri); Desktop.getDesktop().mail(uri); } catch (URISyntaxException ex) { ex.printStackTrace(); } catch (IOException ex) { ex.printStackTrace(); } } }); JPanel buttonPanel = new JPanel(); ((FlowLayout) buttonPanel.getLayout()).setHgap(2); buttonPanel.add(openButton); buttonPanel.add(editButton); buttonPanel.add(printButton); add(fileChooserButton, new GBC(0, 0).setAnchor(GBC.EAST).setInsets(2)); add(fileField, new GBC(1, 0).setFill(GBC.HORIZONTAL)); add(buttonPanel, new GBC(2, 0).setAnchor(GBC.WEST).setInsets(0)); add(browseField, new GBC(1, 1).setFill(GBC.HORIZONTAL)); add(browseButton, new GBC(2, 1).setAnchor(GBC.WEST).setInsets(2)); add(new JLabel("To:"), new GBC(0, 2).setAnchor(GBC.EAST).setInsets(5, 2, 5, 2)); add(toField, new GBC(1, 2).setFill(GBC.HORIZONTAL)); add(mailButton, new GBC(2, 2).setAnchor(GBC.WEST).setInsets(2)); add(new JLabel("Subject:"), new GBC(0, 3).setAnchor(GBC.EAST).setInsets(5, 2, 5, 2)); add(subjectField, new GBC(1, 3).setFill(GBC.HORIZONTAL)); pack(); }
From source file:logdruid.ui.RecordingList.java
/** * Create the panel.//from ww w . ja va2 s. co m */ public RecordingList(final Repository rep) { if (Preferences.getPreference("timings").equals("true")) { header = (String[]) new String[] { "name", "regexp", "type", "active", "success time", "failed time", "match attempt", "success match" }; } else { header = (String[]) new String[] { "name", "regexp", "type", "active" }; } records = rep.getRecordings(); // Collections.sort(records); Iterator it = records.iterator(); while (it.hasNext()) { Recording record = (Recording) it.next(); stats = DataVault.getRecordingStats(record.getName()); if (stats != null) { data.add(new Object[] { record.getName(), record.getRegexp(), record.getType(), record.getIsActive(), stats[0], stats[1], stats[2], stats[3] }); } else { data.add(new Object[] { record.getName(), record.getRegexp(), record.getType(), record.getIsActive(), 0, 0, 0, 0 }); } } repository = rep; model = new MyTableModel2(data, header); JPanel panel_1 = new JPanel(); GridBagConstraints gbc_panel_1 = new GridBagConstraints(); gbc_panel_1.fill = GridBagConstraints.BOTH; gbc_panel_1.insets = new Insets(5, 0, 5, 5); gbc_panel_1.gridx = 1; gbc_panel_1.gridy = 0; panel_1.setLayout(new BorderLayout(0, 0)); table = new JTable(model); JScrollPane scrollPane = new JScrollPane(table); int column; panel_1.add(scrollPane); table.setPreferredScrollableViewportSize(new Dimension(0, 150)); table.setFillsViewportHeight(true); // Set up column sizes. initColumnSizes(table); table.setAutoCreateRowSorter(true); // RowSorter sorter = table.getRowSorter(); // sorter.setSortKeys(Arrays.asList(new RowSorter.SortKey(0, SortOrder.ASCENDING))); if (model.getRowCount() > 0) { table.getRowSorter().toggleSortOrder(0); table.getRowSorter().toggleSortOrder(2); } table.getSelectionModel().addListSelectionListener(new ListSelectionListener() { public void valueChanged(ListSelectionEvent e) { int selectedRow = ((table.getSelectedRow() != -1) ? table.convertRowIndexToModel(table.getSelectedRow()) : -1); ; logger.info("ListSelectionListener - selectedRow: " + selectedRow); if (selectedRow >= 0) { if (jPanelDetail != null) { logger.info("ListSelectionListener - valueChanged"); jPanelDetail.removeAll(); recEditor = getEditor(repository.getRecording(selectedRow)); if (recEditor != null) { jPanelDetail.add(recEditor, BorderLayout.CENTER); } jPanelDetail.revalidate(); } } } }); JPanel panel = new JPanel(); FlowLayout flowLayout = (FlowLayout) panel.getLayout(); flowLayout.setAlignment(FlowLayout.LEFT); flowLayout.setVgap(2); flowLayout.setHgap(2); panel_1.add(panel, BorderLayout.SOUTH); JButton btnNewMeta = new JButton("New Meta"); panel.add(btnNewMeta); btnNewMeta.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { int rowCount = table.getRowCount(); jPanelDetail.removeAll(); Recording re = new MetadataRecording("name", "regex", "example line", "", true, null); recEditor = new MetadataRecordingEditor(thiis, repository, "the line", "regex", (MetadataRecording) re); jPanelDetail.add(recEditor, BorderLayout.CENTER); repository.addRecording(re); model.addRow( new Object[] { re.getName(), re.getRegexp(), re.getType(), re.getIsActive(), 0, 0, 0, 0 }); model.fireTableRowsInserted(rowCount, rowCount); table.setRowSelectionInterval(rowCount, rowCount); logger.info("New record - row count : " + rowCount); } }); JButton btnDuplicate = new JButton("Duplicate"); btnDuplicate.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { int rowCount = table.getRowCount(); int selectRow = ((table.getSelectedRow() != -1) ? table.getSelectedRow() : -1); int selectedRow = ((table.getSelectedRow() != -1) ? table.convertRowIndexToModel(table.getSelectedRow()) : -1); repository.addRecording( repository.getRecording(table.convertRowIndexToModel(table.getSelectedRow())).duplicate()); model.fireTableRowsInserted(rowCount, rowCount); table.setRowSelectionInterval(selectRow, selectRow); } }); JButton btnNewStat = new JButton("New Stat"); btnNewStat.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { int rowCount = table.getRowCount(); jPanelDetail.removeAll(); Recording re = new StatRecording("name", "regex", "example line", "", true, null); recEditor = new StatRecordingEditor(thiis, repository, "the line", "regex", (StatRecording) re); jPanelDetail.add(recEditor, BorderLayout.CENTER); repository.addRecording(re); model.addRow( new Object[] { re.getName(), re.getRegexp(), re.getType(), re.getIsActive(), 0, 0, 0, 0 }); model.fireTableRowsInserted(rowCount, rowCount); table.setRowSelectionInterval(rowCount, rowCount); logger.info("New record - row count : " + rowCount); } }); panel.add(btnNewStat); JButton btnNewEvent = new JButton("New Event"); btnNewEvent.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { int rowCount = table.getRowCount(); logger.info("table.getRowCount()" + table.getRowCount()); jPanelDetail.removeAll(); Recording re = new EventRecording("name", "regex", "example line", "", true, null); recEditor = new EventRecordingEditor(thiis, repository, "the line", "regex", (EventRecording) re); jPanelDetail.add(recEditor, BorderLayout.CENTER); repository.addRecording(re); model.addRow( new Object[] { re.getName(), re.getRegexp(), re.getType(), re.getIsActive(), 0, 0, 0, 0 }); model.fireTableRowsInserted(rowCount, rowCount); table.setRowSelectionInterval(rowCount, rowCount); logger.info("New record - row count : " + rowCount); } }); panel.add(btnNewEvent); panel.add(btnDuplicate); JButton btnDelete = new JButton("Delete"); btnDelete.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { int rowCount = table.getRowCount(); int selectedRow = ((table.getSelectedRow() != -1) ? table.convertRowIndexToModel(table.getSelectedRow()) : -1); ; int realSelectedRow = table.getSelectedRow(); logger.info("selectedRow : " + selectedRow + ", row count: " + table.getRowCount()); if (rowCount != 0) { repository.deleteRecording(selectedRow); model.fireTableRowsDeleted(selectedRow, selectedRow); // table.remove(selectedRow); if (realSelectedRow != -1) { if (realSelectedRow != 0) table.setRowSelectionInterval(realSelectedRow - 1, realSelectedRow - 1); else if (realSelectedRow > 0) table.setRowSelectionInterval(realSelectedRow, realSelectedRow); else if (rowCount > 1) table.setRowSelectionInterval(0, 0); } /* if (table.getRowCount() > 0) { if (selectedRow == table.getRowCount()) { table.setRowSelectionInterval(selectedRow - 1, selectedRow - 1); } else table.setRowSelectionInterval(selectedRow, selectedRow); }*/ } } }); panel.add(btnDelete); setLayout(new BorderLayout(0, 0)); JSplitPane splitPane = new JSplitPane(); splitPane.setOrientation(JSplitPane.VERTICAL_SPLIT); add(splitPane, BorderLayout.CENTER); jPanelDetail = new JPanel(); GridBagConstraints gbc_jPanelDetail = new GridBagConstraints(); gbc_jPanelDetail.insets = new Insets(0, 0, 0, 5); gbc_jPanelDetail.fill = GridBagConstraints.BOTH; gbc_jPanelDetail.gridx = 1; gbc_jPanelDetail.gridy = 4; splitPane.setBottomComponent(jPanelDetail); splitPane.setTopComponent(panel_1); jPanelDetail.setLayout(new BorderLayout(0, 0)); if (repository.getRecordingCount() > 0) { //recEditor = getEditor(repository.getRecording(0)); //jPanelDetail.add(recEditor, BorderLayout.CENTER); table.setRowSelectionInterval(0, 0); } jPanelDetail.revalidate(); }
From source file:au.org.ala.delta.editor.ui.ActionSetsDialog.java
private void createUI() { setName("actionSetsDialog"); tabbedPane = new JTabbedPane(JTabbedPane.TOP); getContentPane().add(tabbedPane, BorderLayout.CENTER); conforTable = new JTable(); tabbedPane.addTab(_resources.getString("directiveTypeConfor.text"), new JScrollPane(conforTable)); intkeyTable = new JTable(); tabbedPane.addTab(_resources.getString("directiveTypeIntkey.text"), new JScrollPane(intkeyTable)); distTable = new JTable(); tabbedPane.addTab(_resources.getString("directiveTypeDist.text"), new JScrollPane(distTable)); keyTable = new JTable(); tabbedPane.addTab(_resources.getString("directiveTypeKey.text"), new JScrollPane(keyTable)); JPanel buttonPanel = new JPanel(); getContentPane().add(buttonPanel, BorderLayout.EAST); runButton = new JButton(); addButton = new JButton(); editButton = new JButton(); deleteButton = new JButton(); doneButton = new JButton(); GroupLayout gl_buttonPanel = new GroupLayout(buttonPanel); gl_buttonPanel.setHorizontalGroup(gl_buttonPanel.createParallelGroup(Alignment.LEADING) .addComponent(runButton, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(addButton, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(editButton, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(deleteButton, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(doneButton, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)); gl_buttonPanel.setVerticalGroup(gl_buttonPanel.createParallelGroup(Alignment.LEADING) .addGroup(gl_buttonPanel.createSequentialGroup().addComponent(runButton).addComponent(addButton) .addComponent(editButton).addComponent(deleteButton).addComponent(doneButton))); buttonPanel.setLayout(gl_buttonPanel); JPanel labelPanel = new JPanel(); FlowLayout flowLayout = (FlowLayout) labelPanel.getLayout(); flowLayout.setHgap(20);/*from www .ja v a 2 s.c om*/ flowLayout.setAlignment(FlowLayout.LEFT); getContentPane().add(labelPanel, BorderLayout.NORTH); JLabel actionSetLabel = new JLabel(); actionSetLabel.setName("actionSetsActionSetsLabel"); labelPanel.add(actionSetLabel); actionSetDetailsLabel = new JLabel(""); labelPanel.add(actionSetDetailsLabel); }
From source file:logdruid.ui.DateEditor.java
/** * Create the panel.// w w w . j a v a 2 s .c o m */ public DateEditor(Repository rep) { repository = rep; model = new MyTableModel2(data, header); GridBagLayout gridBagLayout = new GridBagLayout(); gridBagLayout.columnWidths = new int[] { 15, 550, 15 }; gridBagLayout.rowHeights = new int[] { 152, 300 }; gridBagLayout.columnWeights = new double[] { 0.0, 1.0, 0.0 }; gridBagLayout.rowWeights = new double[] { 0.0, 1.0 }; setLayout(gridBagLayout); JPanel panel_1 = new JPanel(); GridBagConstraints gbc_panel_1 = new GridBagConstraints(); gbc_panel_1.fill = GridBagConstraints.BOTH; gbc_panel_1.insets = new Insets(5, 0, 5, 5); gbc_panel_1.gridx = 1; gbc_panel_1.gridy = 0; add(panel_1, gbc_panel_1); panel_1.setLayout(new BorderLayout(0, 0)); table = new JTable(model); table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); table.setBorder(UIManager.getBorder("TextPane.border")); table.setPreferredScrollableViewportSize(new Dimension(0, 0)); table.setFillsViewportHeight(true); table.getSelectionModel().addListSelectionListener(new ListSelectionListener() { public void valueChanged(ListSelectionEvent e) { // ((table.getSelectedRow()!=-1)?table.convertRowIndexToModel(table.getSelectedRow()):-1) // persist repository // display selected row if (((table.getSelectedRow() != -1) ? table.convertRowIndexToModel(table.getSelectedRow()) : -1) >= 0) { /* * recEditor = new RecordingEditor(repository * .getRecordings().get(((table.getSelectedRow()!=-1)?table. * convertRowIndexToModel(table.getSelectedRow()):-1)), * repository); jPanelDetail.removeAll(); */ // jPanelDetail.add(recEditor, gbc_jPanelDetail); DateFormat df = repository.getDateFormat( ((table.getSelectedRow() != -1) ? table.convertRowIndexToModel(table.getSelectedRow()) : -1)); if (df != null) { textFieldName.setText((String) df.getName()); textFieldPattern.setText((String) df.getPattern()); textField.setText((String) df.getDateFormat()); } // jPanelDetail.revalidate(); // jPanelDetail.repaint(); // jPanelDetail.setVisible(true); // reloadTable(); those 2 ******** // jPanelDetail.revalidate(); } } }); JScrollPane scrollPane = new JScrollPane(table); panel_1.add(scrollPane, BorderLayout.CENTER); // Set up column sizes. initColumnSizes(table); JPanel panel = new JPanel(); FlowLayout flowLayout = (FlowLayout) panel.getLayout(); flowLayout.setAlignment(FlowLayout.LEFT); flowLayout.setVgap(2); flowLayout.setHgap(2); panel_1.add(panel, BorderLayout.SOUTH); JButton btnNew = new JButton("New"); panel.add(btnNew); btnNew.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { DateFormat df = new DateFormat("name", "\\w{3}\\s[0-9]{1}/[0-9]{2}/[0-9]{2}\\s\\d\\d:\\d\\d:\\d\\d", "EEE. MM/dd/yy HH:mm:ss"); repository.addDateFormat(df); data.add(new Object[] { df.getName(), df.getPattern(), df.getDateFormat() }); table.repaint(); } }); JButton btnDuplicate = new JButton("Duplicate"); btnDuplicate.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { if (((table.getSelectedRow() != -1) ? table.convertRowIndexToModel(table.getSelectedRow()) : -1) >= 0) { DateFormat df = repository.getDateFormat( ((table.getSelectedRow() != -1) ? table.convertRowIndexToModel(table.getSelectedRow()) : -1)); repository.addDateFormat(df); reloadTable(); // data.add(new Object[] { table.getRowCount()+1, // df.getName(),df.getDateFormat()}); table.repaint(); } } }); panel.add(btnDuplicate); JButton btnDelete = new JButton("Delete"); btnDelete.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { int selectedRow = ((table.getSelectedRow() != -1) ? table.convertRowIndexToModel(table.getSelectedRow()) : -1); if (selectedRow >= 0) { repository.deleteDateFormat( ((table.getSelectedRow() != -1) ? table.convertRowIndexToModel(table.getSelectedRow()) : -1)); data.remove( ((table.getSelectedRow() != -1) ? table.convertRowIndexToModel(table.getSelectedRow()) : -1)); reloadTable(); table.setRowSelectionInterval(selectedRow, selectedRow); table.repaint(); } } }); panel.add(btnDelete); jPanelDetail = new JPanel(); gbc_jPanelDetail = new GridBagConstraints(); gbc_jPanelDetail.anchor = GridBagConstraints.NORTH; gbc_jPanelDetail.fill = GridBagConstraints.HORIZONTAL; gbc_jPanelDetail.gridx = 1; gbc_jPanelDetail.gridy = 1; add(jPanelDetail, gbc_jPanelDetail); GridBagLayout gbl_jPanelDetail = new GridBagLayout(); gbl_jPanelDetail.columnWidths = new int[] { 169 }; gbl_jPanelDetail.rowHeights = new int[] { 0, 0, 0, 0, 150, 0 }; gbl_jPanelDetail.columnWeights = new double[] { 1.0, 0.0 }; gbl_jPanelDetail.rowWeights = new double[] { 0.0, 0.0, 0.0, 1.0, 1.0, 0.0 }; jPanelDetail.setLayout(gbl_jPanelDetail); JPanel panel_2 = new JPanel(); panel_2.setBorder(null); GridBagConstraints gbc_panel_2 = new GridBagConstraints(); gbc_panel_2.gridwidth = 2; gbc_panel_2.anchor = GridBagConstraints.NORTHWEST; gbc_panel_2.insets = new Insets(0, 0, 5, 0); gbc_panel_2.gridx = 0; gbc_panel_2.gridy = 0; jPanelDetail.add(panel_2, gbc_panel_2); panel_2.setLayout(new FlowLayout(FlowLayout.LEFT, 5, 5)); JLabel label = new JLabel("Name"); panel_2.add(label); textFieldName = new JTextField(); textFieldName.setColumns(20); panel_2.add(textFieldName); JPanel panel_3 = new JPanel(); FlowLayout flowLayout_1 = (FlowLayout) panel_3.getLayout(); flowLayout_1.setAlignment(FlowLayout.LEFT); panel_3.setBorder(null); GridBagConstraints gbc_panel_3 = new GridBagConstraints(); gbc_panel_3.insets = new Insets(0, 0, 5, 0); gbc_panel_3.gridwidth = 2; gbc_panel_3.anchor = GridBagConstraints.NORTHWEST; gbc_panel_3.gridx = 0; gbc_panel_3.gridy = 1; jPanelDetail.add(panel_3, gbc_panel_3); labelPattern = new JLabel("Pattern"); panel_3.add(labelPattern); textFieldPattern = new JTextField(); textFieldPattern.setColumns(40); panel_3.add(textFieldPattern); JButton btnSave = new JButton("Save"); btnSave.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { DateFormat df1 = repository.getDateFormat( ((table.getSelectedRow() != -1) ? table.convertRowIndexToModel(table.getSelectedRow()) : -1)); df1.update(textFieldName.getText(), textFieldPattern.getText(), textField.getText()); reloadTable(); } }); JPanel panel_4 = new JPanel(); FlowLayout flowLayout_2 = (FlowLayout) panel_4.getLayout(); flowLayout_2.setAlignment(FlowLayout.LEFT); GridBagConstraints gbc_panel_4 = new GridBagConstraints(); gbc_panel_4.anchor = GridBagConstraints.WEST; gbc_panel_4.insets = new Insets(0, 0, 5, 5); gbc_panel_4.gridx = 0; gbc_panel_4.gridy = 2; jPanelDetail.add(panel_4, gbc_panel_4); JLabel lblFastDateFormat = new JLabel("FastDateFormat"); panel_4.add(lblFastDateFormat); textField = new JTextField(); panel_4.add(textField); textField.setColumns(30); JPanel panel_5 = new JPanel(); FlowLayout flowLayout_3 = (FlowLayout) panel_5.getLayout(); flowLayout_3.setAlignment(FlowLayout.LEFT); GridBagConstraints gbc_panel_5 = new GridBagConstraints(); gbc_panel_5.insets = new Insets(0, 0, 5, 5); gbc_panel_5.fill = GridBagConstraints.BOTH; gbc_panel_5.gridx = 0; gbc_panel_5.gridy = 3; jPanelDetail.add(panel_5, gbc_panel_5); JLabel lblSampleLabel = new JLabel("Sample"); panel_5.add(lblSampleLabel); JPanel panel_6 = new JPanel(); panel_6.setBorder(new EtchedBorder(EtchedBorder.LOWERED, null, null)); GridBagConstraints gbc_panel_6 = new GridBagConstraints(); gbc_panel_6.ipady = 1; gbc_panel_6.ipadx = 1; gbc_panel_6.insets = new Insets(0, 0, 5, 5); gbc_panel_6.fill = GridBagConstraints.BOTH; gbc_panel_6.gridx = 0; gbc_panel_6.gridy = 4; jPanelDetail.add(panel_6, gbc_panel_6); panel_6.setLayout(new BorderLayout(0, 0)); JTextPane textPane = new JTextPane(); textPane.setBackground(UIManager.getColor("windowBorder")); panel_6.add(textPane); GridBagConstraints gbc_btnSave = new GridBagConstraints(); gbc_btnSave.anchor = GridBagConstraints.WEST; gbc_btnSave.insets = new Insets(0, 0, 0, 5); gbc_btnSave.gridx = 0; gbc_btnSave.gridy = 5; jPanelDetail.add(btnSave, gbc_btnSave); reloadTable(); }
From source file:graphics.MainWindow.java
private void createSecondPanel(JPanel panel, int pos) { JPanel secondPanel = new JPanel(); secondPanel.setBackground(new Color(157, 191, 160)); panel.add("FieldPanel", secondPanel); JPanel Panel = new JPanel(); Panel.setBackground(new Color(157, 191, 160)); this.buttonDifusion[pos] = new JButton("Difusion Rates"); this.buttonDifusion[pos].addActionListener(this); Panel.add(this.buttonDifusion[pos]); panel.add("DifusionPanel", Panel); ((CardLayout) panel.getLayout()).show(panel, "DifusionPanel"); }
From source file:cool.pandora.modeller.ui.jpanel.base.BagView.java
/** * createBagPanel./* w ww . j a v a 2 s .c om*/ * * @return splitPane */ private JSplitPane createBagPanel() { final LineBorder border = new LineBorder(Color.GRAY, 1); bagButtonPanel = createBagButtonPanel(); final JPanel bagTagButtonPanel = createBagTagButtonPanel(); bagPayloadTree = new BagTree(this, AbstractBagConstants.DATA_DIRECTORY); bagPayloadTree.setEnabled(false); bagPayloadTreePanel = new BagTreePanel(bagPayloadTree); bagPayloadTreePanel.setEnabled(false); bagPayloadTreePanel.setBorder(border); bagPayloadTreePanel.setToolTipText(getMessage("bagTree.help")); bagTagFileTree = new BagTree(this, getMessage("bag.label.noname")); bagTagFileTree.setEnabled(false); bagTagFileTreePanel = new BagTreePanel(bagTagFileTree); bagTagFileTreePanel.setEnabled(false); bagTagFileTreePanel.setBorder(border); bagTagFileTreePanel.setToolTipText(getMessage("bagTree.help")); tagManifestPane = new TagManifestPane(this); tagManifestPane.setToolTipText(getMessage("compositePane.tab.help")); final JSplitPane splitPane = new JSplitPane(); splitPane.setResizeWeight(0.5); splitPane.setOrientation(JSplitPane.VERTICAL_SPLIT); final JPanel payloadPannel = new JPanel(); splitPane.setLeftComponent(payloadPannel); payloadPannel.setLayout(new BorderLayout(0, 0)); final JPanel payLoadToolBarPanel = new JPanel(); payloadPannel.add(payLoadToolBarPanel, BorderLayout.NORTH); payLoadToolBarPanel.setLayout(new GridLayout(1, 0, 0, 0)); final JPanel payloadLabelPanel = new JPanel(); final FlowLayout flowLayout = (FlowLayout) payloadLabelPanel.getLayout(); flowLayout.setAlignment(FlowLayout.LEFT); payLoadToolBarPanel.add(payloadLabelPanel); final JLabel lblPayloadTree = new JLabel(getMessage("bagView.payloadTree.name")); payloadLabelPanel.add(lblPayloadTree); payLoadToolBarPanel.add(bagButtonPanel); payloadPannel.add(bagPayloadTreePanel, BorderLayout.CENTER); final JPanel tagFilePanel = new JPanel(); splitPane.setRightComponent(tagFilePanel); tagFilePanel.setLayout(new BorderLayout(0, 0)); final JPanel tagFileToolBarPannel = new JPanel(); tagFilePanel.add(tagFileToolBarPannel, BorderLayout.NORTH); tagFileToolBarPannel.setLayout(new GridLayout(0, 2, 0, 0)); final JPanel TagFileLabelPanel = new JPanel(); final FlowLayout tagFileToolbarFlowLayout = (FlowLayout) TagFileLabelPanel.getLayout(); tagFileToolbarFlowLayout.setAlignment(FlowLayout.LEFT); tagFileToolBarPannel.add(TagFileLabelPanel); final JLabel tagFileTreeLabel = new JLabel(getMessage("bagView.TagFilesTree.name")); TagFileLabelPanel.add(tagFileTreeLabel); tagFileToolBarPannel.add(bagTagButtonPanel); tagFilePanel.add(bagTagFileTreePanel, BorderLayout.CENTER); return splitPane; }
From source file:graphics.MainWindow.java
private void createChartPanel(JPanel panel, final int pos) { JPanel Panel = new JPanel(); Panel.setBackground(new Color(157, 191, 160)); final ChartPanel chart = this.World.getChart(pos); chart.setPreferredSize(new Dimension(100, 100)); Panel.add(chart);/* w ww. ja v a 2s. co m*/ chart.addMouseListener(new MouseListener() { public void mouseClicked(MouseEvent arg0) { World.showChart(pos); } public void mousePressed(MouseEvent arg0) { World.showChart(pos); } public void mouseReleased(MouseEvent arg0) { World.showChart(pos); } public void mouseEntered(MouseEvent arg0) { } public void mouseExited(MouseEvent arg0) { } }); panel.add("ChartPanel", Panel); ((CardLayout) panel.getLayout()).show(panel, "ChartPanel"); }
From source file:com.googlecode.libautocaptcha.tools.VodafoneItalyTool.java
private void initFrame() { frame = new JFrame(); frame.setTitle("libautocaptcha vodafone.it tool"); frame.setBounds(100, 100, 450, 300); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); tabbedPane = new JTabbedPane(JTabbedPane.TOP); frame.getContentPane().add(tabbedPane, BorderLayout.CENTER); JPanel setupPanel = new JPanel(); FlowLayout flowLayout = (FlowLayout) setupPanel.getLayout(); flowLayout.setAlignment(FlowLayout.LEFT); tabbedPane.addTab("Setup", null, setupPanel, null); JPanel setupFormPanel = new JPanel(); setupPanel.add(setupFormPanel);/*from www . j a v a 2 s. c om*/ GridBagLayout gbl_setupFormPanel = new GridBagLayout(); gbl_setupFormPanel.columnWidths = new int[] { 150, 250 }; gbl_setupFormPanel.rowHeights = new int[] { 0, 0, 0 }; gbl_setupFormPanel.columnWeights = new double[] { 0.0, 1.0 }; gbl_setupFormPanel.rowWeights = new double[] { 0.0, 0.0, 0.0 }; setupFormPanel.setLayout(gbl_setupFormPanel); JLabel usernameLabel = new JLabel("Username"); GridBagConstraints gbc_usernameLabel = new GridBagConstraints(); gbc_usernameLabel.anchor = GridBagConstraints.WEST; gbc_usernameLabel.fill = GridBagConstraints.VERTICAL; gbc_usernameLabel.insets = new Insets(0, 0, 5, 5); gbc_usernameLabel.gridx = 0; gbc_usernameLabel.gridy = 0; setupFormPanel.add(usernameLabel, gbc_usernameLabel); usernameField = new JTextField(); GridBagConstraints gbc_usernameField = new GridBagConstraints(); gbc_usernameField.fill = GridBagConstraints.BOTH; gbc_usernameField.insets = new Insets(0, 0, 5, 0); gbc_usernameField.gridx = 1; gbc_usernameField.gridy = 0; setupFormPanel.add(usernameField, gbc_usernameField); usernameField.setColumns(10); JLabel passwordLabel = new JLabel("Password"); GridBagConstraints gbc_passwordLabel = new GridBagConstraints(); gbc_passwordLabel.anchor = GridBagConstraints.WEST; gbc_passwordLabel.fill = GridBagConstraints.VERTICAL; gbc_passwordLabel.insets = new Insets(0, 0, 5, 5); gbc_passwordLabel.gridx = 0; gbc_passwordLabel.gridy = 1; setupFormPanel.add(passwordLabel, gbc_passwordLabel); passwordField = new JPasswordField(); GridBagConstraints gbc_passwordField = new GridBagConstraints(); gbc_passwordField.fill = GridBagConstraints.BOTH; gbc_passwordField.insets = new Insets(0, 0, 5, 0); gbc_passwordField.gridx = 1; gbc_passwordField.gridy = 1; setupFormPanel.add(passwordField, gbc_passwordField); passwordField.setColumns(10); JLabel receiverLabel = new JLabel("Mobile number"); GridBagConstraints gbc_receiverLabel = new GridBagConstraints(); gbc_receiverLabel.fill = GridBagConstraints.VERTICAL; gbc_receiverLabel.anchor = GridBagConstraints.WEST; gbc_receiverLabel.insets = new Insets(0, 0, 5, 5); gbc_receiverLabel.gridx = 0; gbc_receiverLabel.gridy = 2; setupFormPanel.add(receiverLabel, gbc_receiverLabel); receiverField = new JTextField(); GridBagConstraints gbc_receiverField = new GridBagConstraints(); gbc_receiverField.insets = new Insets(0, 0, 5, 0); gbc_receiverField.fill = GridBagConstraints.BOTH; gbc_receiverField.gridx = 1; gbc_receiverField.gridy = 2; setupFormPanel.add(receiverField, gbc_receiverField); receiverField.setColumns(10); JPanel backgroundPanel = new JPanel(); FlowLayout flowLayout_1 = (FlowLayout) backgroundPanel.getLayout(); flowLayout_1.setAlignment(FlowLayout.LEFT); tabbedPane.addTab("Background", null, backgroundPanel, null); JPanel backgroundFormPanel = new JPanel(); backgroundPanel.add(backgroundFormPanel); GridBagLayout gbl_backgroundFormPanel = new GridBagLayout(); gbl_backgroundFormPanel.columnWidths = new int[] { 150, 50, 100, 0 }; gbl_backgroundFormPanel.rowHeights = new int[] { 0, 25, 0 }; gbl_backgroundFormPanel.columnWeights = new double[] { 0.0, 0.0, 0.0, Double.MIN_VALUE }; gbl_backgroundFormPanel.rowWeights = new double[] { 0.0, 0.0, Double.MIN_VALUE }; backgroundFormPanel.setLayout(gbl_backgroundFormPanel); JLabel numberLabel = new JLabel("Number of CAPTCHAs"); GridBagConstraints gbc_numberLabel = new GridBagConstraints(); gbc_numberLabel.anchor = GridBagConstraints.WEST; gbc_numberLabel.insets = new Insets(0, 0, 5, 5); gbc_numberLabel.gridx = 0; gbc_numberLabel.gridy = 0; backgroundFormPanel.add(numberLabel, gbc_numberLabel); numberField = new JTextField(); numberField.setText("5"); GridBagConstraints gbc_numberField = new GridBagConstraints(); gbc_numberField.anchor = GridBagConstraints.WEST; gbc_numberField.insets = new Insets(0, 0, 5, 5); gbc_numberField.gridx = 1; gbc_numberField.gridy = 0; backgroundFormPanel.add(numberField, gbc_numberField); numberField.setColumns(3); JButton numberButton = new JButton("Download"); numberButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { int counter = 0; do { BufferedImage captcha = downloadCAPTCHA(); if (captcha != null) { try { int number = new File(tempFolder.getAbsolutePath()).listFiles().length; File file = new File(tempFolder.getAbsolutePath() + "/background_" + number + ".png"); ImageIO.write(captcha, "png", file); Thread.sleep(2500); } catch (Exception x) { x.printStackTrace(); } } } while (++counter < Integer.valueOf(numberField.getText())); Image background = loadBackground(); if (background != null) { backgroundImage.setIcon(new ImageIcon(background)); } } }); GridBagConstraints gbc_numberButton = new GridBagConstraints(); gbc_numberButton.anchor = GridBagConstraints.NORTHWEST; gbc_numberButton.insets = new Insets(0, 0, 5, 0); gbc_numberButton.gridx = 2; gbc_numberButton.gridy = 0; backgroundFormPanel.add(numberButton, gbc_numberButton); JLabel backgroundLabel = new JLabel("Current background"); GridBagConstraints gbc_backgroundLabel = new GridBagConstraints(); gbc_backgroundLabel.anchor = GridBagConstraints.WEST; gbc_backgroundLabel.insets = new Insets(0, 0, 0, 5); gbc_backgroundLabel.gridx = 0; gbc_backgroundLabel.gridy = 1; backgroundFormPanel.add(backgroundLabel, gbc_backgroundLabel); backgroundImage = new JLabel(""); GridBagConstraints gbc_backgroundImage = new GridBagConstraints(); gbc_backgroundImage.anchor = GridBagConstraints.WEST; gbc_backgroundImage.gridwidth = 2; gbc_backgroundImage.insets = new Insets(0, 0, 0, 5); gbc_backgroundImage.gridx = 1; gbc_backgroundImage.gridy = 1; backgroundFormPanel.add(backgroundImage, gbc_backgroundImage); JPanel trainingPanel = new JPanel(); tabbedPane.addTab("Training", null, trainingPanel, null); GridBagLayout gbl_trainingPanel = new GridBagLayout(); gbl_trainingPanel.columnWidths = new int[] { 437, 0 }; gbl_trainingPanel.rowHeights = new int[] { 0, 0, 0 }; gbl_trainingPanel.columnWeights = new double[] { 0.0, Double.MIN_VALUE }; gbl_trainingPanel.rowWeights = new double[] { 0.0, 0.0, Double.MIN_VALUE }; trainingPanel.setLayout(gbl_trainingPanel); trainingLoadPanel = new JPanel(); GridBagConstraints gbc_trainingLoadPanel = new GridBagConstraints(); gbc_trainingLoadPanel.anchor = GridBagConstraints.NORTHWEST; gbc_trainingLoadPanel.insets = new Insets(0, 0, 5, 0); gbc_trainingLoadPanel.gridx = 0; gbc_trainingLoadPanel.gridy = 0; trainingPanel.add(trainingLoadPanel, gbc_trainingLoadPanel); trainingLoadPanel.setLayout(new FlowLayout(FlowLayout.LEFT, 5, 5)); JButton trainingLoadButton = new JButton("Download"); trainingLoadButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { trainingCaptcha = downloadCAPTCHA(); if (trainingCaptcha != null) { trainingCaptchaImage.setIcon(new ImageIcon(trainingCaptcha)); List<Image> glyphs = loadGlyphs(trainingCaptcha); for (int g = 0; g < 5; ++g) { trainingGlyphImage[g].setIcon(null); trainingGlyphField[g].setText(""); } for (int g = 0; g < glyphs.size() && g < 5; ++g) { trainingGlyph[g] = glyphs.get(g); trainingGlyphImage[g].setIcon(new ImageIcon(trainingGlyph[g])); } trainingLoadPanel.invalidate(); trainingSavePanel.invalidate(); } } }); trainingLoadPanel.add(trainingLoadButton); trainingCaptchaImage = new JLabel(""); trainingLoadPanel.add(trainingCaptchaImage); trainingSavePanel = new JPanel(); GridBagConstraints gbc_trainingSavePanel = new GridBagConstraints(); gbc_trainingSavePanel.insets = new Insets(0, 5, 0, 0); gbc_trainingSavePanel.anchor = GridBagConstraints.NORTHWEST; gbc_trainingSavePanel.gridx = 0; gbc_trainingSavePanel.gridy = 1; trainingPanel.add(trainingSavePanel, gbc_trainingSavePanel); GridBagLayout gbl_trainingSavePanel = new GridBagLayout(); gbl_trainingSavePanel.columnWidths = new int[] { 25, 25, 25, 25, 25, 0, 0 }; gbl_trainingSavePanel.rowHeights = new int[] { 25, 0, 0 }; gbl_trainingSavePanel.columnWeights = new double[] { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, Double.MIN_VALUE }; gbl_trainingSavePanel.rowWeights = new double[] { 0.0, 0.0, Double.MIN_VALUE }; trainingSavePanel.setLayout(gbl_trainingSavePanel); trainingGlyph = new Image[5]; trainingGlyphImage = new JLabel[5]; trainingGlyphField = new JTextField[5]; trainingGlyphImage[0] = new JLabel(""); GridBagConstraints gbc_glyphImage0 = new GridBagConstraints(); gbc_glyphImage0.anchor = GridBagConstraints.NORTHWEST; gbc_glyphImage0.insets = new Insets(0, 0, 5, 5); gbc_glyphImage0.gridx = 0; gbc_glyphImage0.gridy = 0; trainingGlyphImage[0].setBorder(BorderFactory.createLineBorder(Color.GRAY, 2)); trainingSavePanel.add(trainingGlyphImage[0], gbc_glyphImage0); trainingGlyphImage[1] = new JLabel(""); GridBagConstraints gbc_glyphImage1 = new GridBagConstraints(); gbc_glyphImage1.anchor = GridBagConstraints.NORTHWEST; gbc_glyphImage1.insets = new Insets(0, 0, 5, 5); gbc_glyphImage1.gridx = 1; gbc_glyphImage1.gridy = 0; trainingGlyphImage[1].setBorder(BorderFactory.createLineBorder(Color.GRAY, 2)); trainingSavePanel.add(trainingGlyphImage[1], gbc_glyphImage1); trainingGlyphImage[2] = new JLabel(""); GridBagConstraints gbc_glyphImage2 = new GridBagConstraints(); gbc_glyphImage2.anchor = GridBagConstraints.NORTHWEST; gbc_glyphImage2.insets = new Insets(0, 0, 5, 5); gbc_glyphImage2.gridx = 2; gbc_glyphImage2.gridy = 0; trainingGlyphImage[2].setBorder(BorderFactory.createLineBorder(Color.GRAY, 2)); trainingSavePanel.add(trainingGlyphImage[2], gbc_glyphImage2); trainingGlyphImage[3] = new JLabel(""); GridBagConstraints gbc_glyphImage3 = new GridBagConstraints(); gbc_glyphImage3.anchor = GridBagConstraints.NORTHWEST; gbc_glyphImage3.insets = new Insets(0, 0, 5, 5); gbc_glyphImage3.gridx = 3; gbc_glyphImage3.gridy = 0; trainingGlyphImage[3].setBorder(BorderFactory.createLineBorder(Color.GRAY, 2)); trainingSavePanel.add(trainingGlyphImage[3], gbc_glyphImage3); trainingGlyphImage[4] = new JLabel(""); GridBagConstraints gbc_glyphImage4 = new GridBagConstraints(); gbc_glyphImage4.insets = new Insets(0, 0, 5, 5); gbc_glyphImage4.anchor = GridBagConstraints.NORTHWEST; gbc_glyphImage4.gridx = 4; gbc_glyphImage4.gridy = 0; trainingGlyphImage[4].setBorder(BorderFactory.createLineBorder(Color.GRAY, 2)); trainingSavePanel.add(trainingGlyphImage[4], gbc_glyphImage4); JButton trainingSaveButton = new JButton("Train"); trainingSaveButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { for (int g = 0; g < 5; ++g) { String s = trainingGlyphField[g].getText(); if (s.length() == 1) { char c = Character.toUpperCase(s.charAt(0)); net.sourceforge.javaocr.Image glyph = convertImage(trainingGlyph[g]); grayFilter.process(glyph); ThresholdFilter thresholdFilter = new ThresholdFilter(0, FG, BG); thresholdFilter.process(glyph); train(glyph, c); } trainingGlyphField[g].setText(""); } for (Map.Entry<Character, Cluster> m : clusters.entrySet()) { System.out.println("****************************************"); System.out.print(" character: "); // int samples = ((EuclidianDistanceCluster) m.getValue()).getAmountSamples(); int samples = ((SigmaWeightedEuclidianDistanceCluster) m.getValue()).getAmountSamples(); for (int s = 0; s < samples; ++s) System.out.print(m.getKey()); System.out.println(); double[] c = m.getValue().center(); for (int i = 0; i < c.length; ++i) System.out.println(" centroid[" + i + "]: " + c[i]); } System.out.println("****************************************"); System.out.println("TOTAL CLUSTERS: " + clusters.size()); } }); GridBagConstraints gbc_trainingSaveButton = new GridBagConstraints(); gbc_trainingSaveButton.gridheight = 2; gbc_trainingSaveButton.insets = new Insets(0, 0, 5, 0); gbc_trainingSaveButton.gridx = 5; gbc_trainingSaveButton.gridy = 0; trainingSavePanel.add(trainingSaveButton, gbc_trainingSaveButton); trainingGlyphField[0] = new JTextField(); GridBagConstraints gbc_glyphField0 = new GridBagConstraints(); gbc_glyphField0.fill = GridBagConstraints.HORIZONTAL; gbc_glyphField0.anchor = GridBagConstraints.NORTHWEST; gbc_glyphField0.insets = new Insets(0, 0, 0, 5); gbc_glyphField0.gridx = 0; gbc_glyphField0.gridy = 1; trainingSavePanel.add(trainingGlyphField[0], gbc_glyphField0); trainingGlyphField[0].setColumns(2); trainingGlyphField[1] = new JTextField(); GridBagConstraints gbc_glyphField1 = new GridBagConstraints(); gbc_glyphField1.fill = GridBagConstraints.HORIZONTAL; gbc_glyphField1.anchor = GridBagConstraints.NORTHWEST; gbc_glyphField1.insets = new Insets(0, 0, 0, 5); gbc_glyphField1.gridx = 1; gbc_glyphField1.gridy = 1; trainingSavePanel.add(trainingGlyphField[1], gbc_glyphField1); trainingGlyphField[1].setColumns(2); trainingGlyphField[2] = new JTextField(); GridBagConstraints gbc_glyphField2 = new GridBagConstraints(); gbc_glyphField2.fill = GridBagConstraints.HORIZONTAL; gbc_glyphField2.anchor = GridBagConstraints.NORTHWEST; gbc_glyphField2.insets = new Insets(0, 0, 0, 5); gbc_glyphField2.gridx = 2; gbc_glyphField2.gridy = 1; trainingSavePanel.add(trainingGlyphField[2], gbc_glyphField2); trainingGlyphField[2].setColumns(2); trainingGlyphField[3] = new JTextField(); GridBagConstraints gbc_glyphField3 = new GridBagConstraints(); gbc_glyphField3.fill = GridBagConstraints.HORIZONTAL; gbc_glyphField3.anchor = GridBagConstraints.NORTHWEST; gbc_glyphField3.insets = new Insets(0, 0, 0, 5); gbc_glyphField3.gridx = 3; gbc_glyphField3.gridy = 1; trainingSavePanel.add(trainingGlyphField[3], gbc_glyphField3); trainingGlyphField[3].setColumns(2); trainingGlyphField[4] = new JTextField(); GridBagConstraints gbc_glyphField4 = new GridBagConstraints(); gbc_glyphField4.insets = new Insets(0, 0, 0, 5); gbc_glyphField4.fill = GridBagConstraints.HORIZONTAL; gbc_glyphField4.anchor = GridBagConstraints.NORTHWEST; gbc_glyphField4.gridx = 4; gbc_glyphField4.gridy = 1; trainingSavePanel.add(trainingGlyphField[4], gbc_glyphField4); trainingGlyphField[4].setColumns(2); JPanel testingPanel = new JPanel(); tabbedPane.addTab("Testing", null, testingPanel, null); GridBagLayout gbl_testingPanel = new GridBagLayout(); gbl_testingPanel.columnWidths = new int[] { 437, 0 }; gbl_testingPanel.rowHeights = new int[] { 0, 0, 0, 0 }; gbl_testingPanel.columnWeights = new double[] { 1.0, Double.MIN_VALUE }; gbl_testingPanel.rowWeights = new double[] { 0.0, 0.0, 1.0, Double.MIN_VALUE }; testingPanel.setLayout(gbl_testingPanel); testingLoadPanel = new JPanel(); GridBagConstraints gbc_testingLoadPanel = new GridBagConstraints(); gbc_testingLoadPanel.anchor = GridBagConstraints.NORTHWEST; gbc_testingLoadPanel.insets = new Insets(0, 0, 5, 0); gbc_testingLoadPanel.gridx = 0; gbc_testingLoadPanel.gridy = 0; testingPanel.add(testingLoadPanel, gbc_testingLoadPanel); testingLoadPanel.setLayout(new FlowLayout(FlowLayout.LEFT, 5, 5)); JButton testingLoadButton = new JButton("Download"); testingLoadButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { testingCaptcha = downloadCAPTCHA(); if (testingCaptcha != null) { testingCaptchaImage.setIcon(new ImageIcon(testingCaptcha)); List<Image> glyphs = loadGlyphs(testingCaptcha); for (int g = 0; g < 5; ++g) { testingGlyphImage[g].setIcon(null); testingGlyphField[g].setText(""); } for (int g = 0; g < glyphs.size() && g < 5; ++g) { testingGlyph[g] = glyphs.get(g); testingGlyphImage[g].setIcon(new ImageIcon(testingGlyph[g])); } testingLoadPanel.invalidate(); testingSavePanel.invalidate(); } } }); testingLoadPanel.add(testingLoadButton); testingCaptchaImage = new JLabel(""); testingLoadPanel.add(testingCaptchaImage); testingSavePanel = new JPanel(); GridBagConstraints gbc_testingSavePanel = new GridBagConstraints(); gbc_testingSavePanel.insets = new Insets(0, 5, 5, 0); gbc_testingSavePanel.anchor = GridBagConstraints.NORTHWEST; gbc_testingSavePanel.gridx = 0; gbc_testingSavePanel.gridy = 1; testingPanel.add(testingSavePanel, gbc_testingSavePanel); GridBagLayout gbl_testingSavePanel = new GridBagLayout(); gbl_testingSavePanel.columnWidths = new int[] { 25, 25, 25, 25, 25, 0, 0 }; gbl_testingSavePanel.rowHeights = new int[] { 25, 0, 0 }; gbl_testingSavePanel.columnWeights = new double[] { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, Double.MIN_VALUE }; gbl_testingSavePanel.rowWeights = new double[] { 0.0, 0.0, Double.MIN_VALUE }; testingSavePanel.setLayout(gbl_testingSavePanel); testingGlyph = new Image[5]; testingGlyphImage = new JLabel[5]; testingGlyphField = new JTextField[5]; testingGlyphImage[0] = new JLabel(""); GridBagConstraints gbc_testingGlyphImage0 = new GridBagConstraints(); gbc_testingGlyphImage0.anchor = GridBagConstraints.NORTHWEST; gbc_testingGlyphImage0.insets = new Insets(0, 0, 5, 5); gbc_testingGlyphImage0.gridx = 0; gbc_testingGlyphImage0.gridy = 0; testingGlyphImage[0].setBorder(BorderFactory.createLineBorder(Color.GRAY, 2)); testingSavePanel.add(testingGlyphImage[0], gbc_testingGlyphImage0); testingGlyphImage[1] = new JLabel(""); GridBagConstraints gbc_testingGlyphImage1 = new GridBagConstraints(); gbc_testingGlyphImage1.anchor = GridBagConstraints.NORTHWEST; gbc_testingGlyphImage1.insets = new Insets(0, 0, 5, 5); gbc_testingGlyphImage1.gridx = 1; gbc_testingGlyphImage1.gridy = 0; testingGlyphImage[1].setBorder(BorderFactory.createLineBorder(Color.GRAY, 2)); testingSavePanel.add(testingGlyphImage[1], gbc_testingGlyphImage1); testingGlyphImage[2] = new JLabel(""); GridBagConstraints gbc_testingGlyphImage2 = new GridBagConstraints(); gbc_testingGlyphImage2.anchor = GridBagConstraints.NORTHWEST; gbc_testingGlyphImage2.insets = new Insets(0, 0, 5, 5); gbc_testingGlyphImage2.gridx = 2; gbc_testingGlyphImage2.gridy = 0; testingGlyphImage[2].setBorder(BorderFactory.createLineBorder(Color.GRAY, 2)); testingSavePanel.add(testingGlyphImage[2], gbc_testingGlyphImage2); testingGlyphImage[3] = new JLabel(""); GridBagConstraints gbc_testingGlyphImage3 = new GridBagConstraints(); gbc_testingGlyphImage3.anchor = GridBagConstraints.NORTHWEST; gbc_testingGlyphImage3.insets = new Insets(0, 0, 5, 5); gbc_testingGlyphImage3.gridx = 3; gbc_testingGlyphImage3.gridy = 0; testingGlyphImage[3].setBorder(BorderFactory.createLineBorder(Color.GRAY, 2)); testingSavePanel.add(testingGlyphImage[3], gbc_testingGlyphImage3); testingGlyphImage[4] = new JLabel(""); GridBagConstraints gbc_testingGlyphImage4 = new GridBagConstraints(); gbc_testingGlyphImage4.insets = new Insets(0, 0, 5, 5); gbc_testingGlyphImage4.anchor = GridBagConstraints.NORTHWEST; gbc_testingGlyphImage4.gridx = 4; gbc_testingGlyphImage4.gridy = 0; testingGlyphImage[4].setBorder(BorderFactory.createLineBorder(Color.GRAY, 2)); testingSavePanel.add(testingGlyphImage[4], gbc_testingGlyphImage4); JButton testingSaveButton = new JButton("Save and test"); testingSaveButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { String text = ""; for (int g = 0; g < 5; ++g) { String s = testingGlyphField[g].getText(); if (s.length() == 1) text += s.toUpperCase(); trainingGlyphField[g].setText(""); } if (text.length() != 5) return; try { File file = new File(tempFolder.getAbsolutePath() + "/captcha_" + text + ".png"); ImageIO.write(testingCaptcha, "png", file); } catch (IOException x) { x.printStackTrace(); } testingViewArea.setText(loadStatistics()); } }); GridBagConstraints gbc_testingSaveButton = new GridBagConstraints(); gbc_testingSaveButton.gridheight = 2; gbc_testingSaveButton.insets = new Insets(0, 0, 5, 0); gbc_testingSaveButton.gridx = 5; gbc_testingSaveButton.gridy = 0; testingSavePanel.add(testingSaveButton, gbc_testingSaveButton); testingGlyphField[0] = new JTextField(); GridBagConstraints gbc_testingGlyphField0 = new GridBagConstraints(); gbc_testingGlyphField0.fill = GridBagConstraints.HORIZONTAL; gbc_testingGlyphField0.anchor = GridBagConstraints.NORTHWEST; gbc_testingGlyphField0.insets = new Insets(0, 0, 0, 5); gbc_testingGlyphField0.gridx = 0; gbc_testingGlyphField0.gridy = 1; testingSavePanel.add(testingGlyphField[0], gbc_testingGlyphField0); testingGlyphField[0].setColumns(2); testingGlyphField[1] = new JTextField(); GridBagConstraints gbc_testingGlyphField1 = new GridBagConstraints(); gbc_testingGlyphField1.fill = GridBagConstraints.HORIZONTAL; gbc_testingGlyphField1.anchor = GridBagConstraints.NORTHWEST; gbc_testingGlyphField1.insets = new Insets(0, 0, 0, 5); gbc_testingGlyphField1.gridx = 1; gbc_testingGlyphField1.gridy = 1; testingSavePanel.add(testingGlyphField[1], gbc_testingGlyphField1); testingGlyphField[1].setColumns(2); testingGlyphField[2] = new JTextField(); GridBagConstraints gbc_testingGlyphField2 = new GridBagConstraints(); gbc_testingGlyphField2.fill = GridBagConstraints.HORIZONTAL; gbc_testingGlyphField2.anchor = GridBagConstraints.NORTHWEST; gbc_testingGlyphField2.insets = new Insets(0, 0, 0, 5); gbc_testingGlyphField2.gridx = 2; gbc_testingGlyphField2.gridy = 1; testingSavePanel.add(testingGlyphField[2], gbc_testingGlyphField2); testingGlyphField[2].setColumns(2); testingGlyphField[3] = new JTextField(); GridBagConstraints gbc_testingGlyphField3 = new GridBagConstraints(); gbc_testingGlyphField3.fill = GridBagConstraints.HORIZONTAL; gbc_testingGlyphField3.anchor = GridBagConstraints.NORTHWEST; gbc_testingGlyphField3.insets = new Insets(0, 0, 0, 5); gbc_testingGlyphField3.gridx = 3; gbc_testingGlyphField3.gridy = 1; testingSavePanel.add(testingGlyphField[3], gbc_testingGlyphField3); testingGlyphField[3].setColumns(2); testingGlyphField[4] = new JTextField(); GridBagConstraints gbc_testingGlyphField4 = new GridBagConstraints(); gbc_testingGlyphField4.insets = new Insets(0, 0, 0, 5); gbc_testingGlyphField4.fill = GridBagConstraints.HORIZONTAL; gbc_testingGlyphField4.anchor = GridBagConstraints.NORTHWEST; gbc_testingGlyphField4.gridx = 4; gbc_testingGlyphField4.gridy = 1; testingSavePanel.add(testingGlyphField[4], gbc_testingGlyphField4); JPanel testingViewPanel = new JPanel(); GridBagConstraints gbc_testingViewPanel = new GridBagConstraints(); gbc_testingViewPanel.fill = GridBagConstraints.HORIZONTAL; gbc_testingViewPanel.anchor = GridBagConstraints.NORTHWEST; gbc_testingViewPanel.gridx = 0; gbc_testingViewPanel.gridy = 2; testingPanel.add(testingViewPanel, gbc_testingViewPanel); GridBagLayout gbl_testingViewPanel = new GridBagLayout(); gbl_testingViewPanel.columnWidths = new int[] { 330, 0 }; gbl_testingViewPanel.rowHeights = new int[] { 75, 0 }; gbl_testingViewPanel.columnWeights = new double[] { 0.0, Double.MIN_VALUE }; gbl_testingViewPanel.rowWeights = new double[] { 0.0, Double.MIN_VALUE }; testingViewPanel.setLayout(gbl_testingViewPanel); testingViewArea = new JTextArea(); testingViewArea.setRows(5); testingViewArea.setColumns(30); GridBagConstraints gbc_testingViewArea = new GridBagConstraints(); gbc_testingViewArea.fill = GridBagConstraints.BOTH; gbc_testingViewArea.anchor = GridBagConstraints.NORTHWEST; gbc_testingViewArea.gridx = 0; gbc_testingViewArea.gridy = 0; testingViewPanel.add(testingViewArea, gbc_testingViewArea); testingGlyphField[4].setColumns(2); JPanel outputPanel = new JPanel(); FlowLayout flowLayout2 = (FlowLayout) outputPanel.getLayout(); flowLayout2.setAlignment(FlowLayout.LEFT); tabbedPane.addTab("Output", null, outputPanel, null); JPanel outputFormPanel = new JPanel(); outputPanel.add(outputFormPanel); GridBagLayout gbl_outputFormPanel = new GridBagLayout(); gbl_outputFormPanel.columnWidths = new int[] { 150, 250 }; gbl_outputFormPanel.rowHeights = new int[] { 0 }; gbl_outputFormPanel.columnWeights = new double[] { 0.0, 1.0 }; gbl_outputFormPanel.rowWeights = new double[] { 0.0 }; outputFormPanel.setLayout(gbl_outputFormPanel); JLabel javaLabel = new JLabel("Output .java file"); GridBagConstraints gbc_javaLabel = new GridBagConstraints(); gbc_javaLabel.anchor = GridBagConstraints.WEST; gbc_javaLabel.fill = GridBagConstraints.VERTICAL; gbc_javaLabel.insets = new Insets(0, 0, 5, 5); gbc_javaLabel.gridx = 0; gbc_javaLabel.gridy = 0; outputFormPanel.add(javaLabel, gbc_javaLabel); javaField = new JTextField(); javaField.addFocusListener(new FocusListener() { public void focusLost(FocusEvent e) { javaField.removeFocusListener(this); } public void focusGained(FocusEvent e) { JFileChooser chooser = new JFileChooser(outFolderName); chooser.setSelectedFile(new File(outFileName)); chooser.setFileSelectionMode(JFileChooser.FILES_ONLY); if (chooser.showDialog(frame, "Save .java file") == JFileChooser.APPROVE_OPTION) { javaField.setText(chooser.getSelectedFile().getAbsolutePath()); try { PrintWriter output = new PrintWriter( new FileWriter(chooser.getSelectedFile().getAbsolutePath())); output.println("package com.googlecode.libautocaptcha.decoder.data;"); output.println("import net.sourceforge.javaocr.plugin.cluster.Cluster;"); output.println("import net.sourceforge.javaocr.plugin.cluster.MahalanobisDistanceCluster;"); output.println("public class VodafoneItalyData {"); output.println(" public static final int[] " + BACKGROUND_FIELD + " = "); output.print(" new int[] { "); for (int y = 0; y < HEIGHT; ++y) for (int x = 0; x < WIDTH; ++x) output.print(background.get(x, y) + ", "); output.println("};"); output.println(" public static final char[] " + CHARACTERS_FIELD + " = "); output.print(" new char[] { "); for (Character c : clusters.keySet()) output.print("'" + c + "', "); output.println("};"); output.println(" public static final Cluster[] " + CLUSTERS_FIELD + " = "); output.print(" new MahalanobisDistanceCluster[] { "); for (Cluster c : clusters.values()) { output.print("new MahalanobisDistanceCluster(new double[] { "); double[] mx = ((MahalanobisDistanceCluster) c).getMx(); for (double i : mx) output.print(i + ", "); output.print("}, new double[][] { "); double[][] invcov = ((MahalanobisDistanceCluster) c).getInvcov(); for (double[] row : invcov) { output.print("new double[] { "); for (double i : row) output.print(i + ", "); output.print("}, "); } output.print("}), "); } output.println("};"); output.println("}"); output.close(); } catch (IOException x) { x.printStackTrace(); } } } }); GridBagConstraints gbc_javaField = new GridBagConstraints(); gbc_javaField.fill = GridBagConstraints.BOTH; gbc_javaField.insets = new Insets(0, 0, 5, 0); gbc_javaField.gridx = 1; gbc_javaField.gridy = 0; outputFormPanel.add(javaField, gbc_javaField); javaField.setColumns(10); JPanel statusPanel = new JPanel(); frame.getContentPane().add(statusPanel, BorderLayout.SOUTH); GridBagLayout gbl_statusPanel = new GridBagLayout(); gbl_statusPanel.columnWidths = new int[] { 150, 0, 0 }; gbl_statusPanel.rowHeights = new int[] { 14, 0 }; gbl_statusPanel.columnWeights = new double[] { 0.0, 1.0, Double.MIN_VALUE }; gbl_statusPanel.rowWeights = new double[] { 0.0, Double.MIN_VALUE }; statusPanel.setLayout(gbl_statusPanel); statusBar = new JProgressBar(); GridBagConstraints gbc_statusBar = new GridBagConstraints(); gbc_statusBar.insets = new Insets(0, 0, 0, 5); gbc_statusBar.gridx = 0; gbc_statusBar.gridy = 0; statusPanel.add(statusBar, gbc_statusBar); statusLabel = new JLabel(""); GridBagConstraints gbc_statusLabel = new GridBagConstraints(); gbc_statusLabel.fill = GridBagConstraints.HORIZONTAL; gbc_statusLabel.gridx = 1; gbc_statusLabel.gridy = 0; statusPanel.add(statusLabel, gbc_statusLabel); }
From source file:davmail.ui.SettingsFrame.java
protected JPanel getSmartCardPanel() { JPanel clientKeystorePanel = new JPanel(new GridLayout(2, 1)); clientKeystorePanel.setLayout(new BoxLayout(clientKeystorePanel, BoxLayout.Y_AXIS)); clientKeystorePanel/*from w ww . j a va 2 s.com*/ .setBorder(BorderFactory.createTitledBorder(BundleMessage.format("UI_CLIENT_CERTIFICATE"))); clientKeystoreTypeCombo = new JComboBox(new String[] { "PKCS11", "JKS", "PKCS12" }); clientKeystoreTypeCombo.setSelectedItem(Settings.getProperty("davmail.ssl.clientKeystoreType")); clientKeystoreFileField = new JTextField(Settings.getProperty("davmail.ssl.clientKeystoreFile"), 17); clientKeystorePassField = new JPasswordField(Settings.getProperty("davmail.ssl.clientKeystorePass"), 15); pkcs11LibraryField = new JTextField(Settings.getProperty("davmail.ssl.pkcs11Library"), 17); pkcs11ConfigField = new JTextArea(2, 17); pkcs11ConfigField.setText(Settings.getProperty("davmail.ssl.pkcs11Config")); pkcs11ConfigField.setBorder(pkcs11LibraryField.getBorder()); pkcs11ConfigField.setFont(pkcs11LibraryField.getFont()); JPanel clientKeystoreTypePanel = new JPanel(new GridLayout(1, 2)); addSettingComponent(clientKeystoreTypePanel, BundleMessage.format("UI_CLIENT_KEY_STORE_TYPE"), clientKeystoreTypeCombo, BundleMessage.format("UI_CLIENT_KEY_STORE_TYPE_HELP")); clientKeystorePanel.add(clientKeystoreTypePanel); final JPanel cardPanel = new JPanel(new CardLayout()); clientKeystorePanel.add(cardPanel); JPanel clientKeystoreFilePanel = new JPanel(new GridLayout(2, 2)); addSettingComponent(clientKeystoreFilePanel, BundleMessage.format("UI_CLIENT_KEY_STORE"), clientKeystoreFileField, BundleMessage.format("UI_CLIENT_KEY_STORE_HELP")); addSettingComponent(clientKeystoreFilePanel, BundleMessage.format("UI_CLIENT_KEY_STORE_PASSWORD"), clientKeystorePassField, BundleMessage.format("UI_CLIENT_KEY_STORE_PASSWORD_HELP")); cardPanel.add(clientKeystoreFilePanel, "FILE"); JPanel pkcs11Panel = new JPanel(new GridLayout(2, 2)); addSettingComponent(pkcs11Panel, BundleMessage.format("UI_PKCS11_LIBRARY"), pkcs11LibraryField, BundleMessage.format("UI_PKCS11_LIBRARY_HELP")); addSettingComponent(pkcs11Panel, BundleMessage.format("UI_PKCS11_CONFIG"), pkcs11ConfigField, BundleMessage.format("UI_PKCS11_CONFIG_HELP")); cardPanel.add(pkcs11Panel, "PKCS11"); ((CardLayout) cardPanel.getLayout()).show(cardPanel, (String) clientKeystoreTypeCombo.getSelectedItem()); clientKeystoreTypeCombo.addItemListener(new ItemListener() { public void itemStateChanged(ItemEvent event) { CardLayout cardLayout = (CardLayout) (cardPanel.getLayout()); if ("PKCS11".equals(event.getItem())) { cardLayout.show(cardPanel, "PKCS11"); } else { cardLayout.show(cardPanel, "FILE"); } } }); updateMaximumSize(clientKeystorePanel); return clientKeystorePanel; }