List of usage examples for javax.swing JLabel setFont
@BeanProperty(preferred = true, visualUpdate = true, description = "The font for the component.") public void setFont(Font font)
From source file:org.p_vcd.ui.LicenseDialog.java
public LicenseDialog(String libName, String libHomepage, String licenseName, String licenseFilename) { setSize(680, 480);/*from w ww. jav a 2s .c o m*/ setTitle(libName); getContentPane().setLayout(new BorderLayout()); { JPanel panel = new JPanel(); getContentPane().add(panel, BorderLayout.NORTH); panel.setLayout(new MigLayout("", "[grow,trailing][grow]", "[20px][][]")); { JLabel lblSoft = new JLabel(libName); lblSoft.setFont(new Font("Tahoma", Font.BOLD, 16)); panel.add(lblSoft, "center,cell 0 0 2 1"); } { JLabel lblHomePage = new JLabel("Home page:"); lblHomePage.setFont(new Font("Tahoma", Font.BOLD, 14)); panel.add(lblHomePage, "cell 0 1"); } { JLabel lblHome = SwingUtil.createLink(libHomepage, libHomepage); lblHome.setFont(new Font("Tahoma", Font.PLAIN, 14)); panel.add(lblHome, "cell 1 1"); } { JLabel lblNewLabel = new JLabel("License:"); lblNewLabel.setFont(new Font("Tahoma", Font.BOLD, 14)); panel.add(lblNewLabel, "cell 0 2"); } { JLabel lblLicense = new JLabel(licenseName); lblLicense.setFont(new Font("Tahoma", Font.PLAIN, 14)); panel.add(lblLicense, "cell 1 2"); } } { JPanel panel = new JPanel(); getContentPane().add(panel, BorderLayout.CENTER); panel.setLayout(new FlowLayout()); panel.setBorder(new EmptyBorder(5, 5, 5, 5)); JScrollPane scrollPane = new JScrollPane(); scrollPane.setPreferredSize(new Dimension(600, 300)); scrollPane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS); panel.add(scrollPane); { JTextArea txtLicense = new JTextArea(); txtLicense.setEditable(false); txtLicense.setFont(new Font("Monospaced", Font.PLAIN, 11)); txtLicense.setWrapStyleWord(true); txtLicense.setLineWrap(true); try { InputStream is = Thread.currentThread().getContextClassLoader() .getResourceAsStream("org/p_vcd/licenses/" + licenseFilename); String text = IOUtils.toString(is, "UTF-8"); IOUtils.closeQuietly(is); txtLicense.setText(text); txtLicense.setCaretPosition(0); } catch (Exception e) { e.printStackTrace(); } scrollPane.setViewportView(txtLicense); } } { JPanel panel = new JPanel(); getContentPane().add(panel, BorderLayout.SOUTH); panel.setLayout(new FlowLayout(FlowLayout.CENTER)); JButton okButton = new JButton("OK"); okButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { LicenseDialog.this.dispose(); } }); okButton.setActionCommand("OK"); panel.add(okButton); getRootPane().setDefaultButton(okButton); } }
From source file:org.p_vcd.ui.VcdDialog.java
public VcdDialog() { setSize(700, 450);//from ww w .j av a 2s. c om setTitle("P-VCD - Video Copy Detection"); setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); this.currentStep = 1; getContentPane().setLayout(new BorderLayout()); contentPanel.setBorder(new EmptyBorder(5, 5, 5, 5)); getContentPane().add(contentPanel, BorderLayout.CENTER); contentPanel.setLayout(new CardLayout(0, 0)); { JPanel panel_Step1 = new JPanel(); contentPanel.add(panel_Step1, "card_step1"); panel_Step1.setLayout(new BorderLayout(0, 0)); JLabel lblTitle = new JLabel("STEP 1 - Video Database (the \"known\")"); panel_Step1.add(lblTitle, BorderLayout.NORTH); lblTitle.setHorizontalAlignment(SwingConstants.CENTER); lblTitle.setFont(new Font("Tahoma", Font.PLAIN, 18)); JPanel panel_1 = new JPanel(); panel_Step1.add(panel_1, BorderLayout.CENTER); panel_1.setLayout(new MigLayout("", "[250px,grow][20px][250px,grow]", "[][][230px,grow][][][]")); JLabel lblNewLabel = new JLabel("Please select the video databases to search in:"); panel_1.add(lblNewLabel, "cell 0 0"); panel_1.add(lbl_refDbTitle, "cell 2 1"); JScrollPane scrollPane_1 = new JScrollPane(); panel_1.add(scrollPane_1, "cell 0 1 1 3,grow"); panel_refDatabasesList.setBackground(Color.WHITE); scrollPane_1.setViewportView(panel_refDatabasesList); panel_refDatabasesList.setLayout(new MigLayout("gapy 10", "[200px]", "[][]")); JScrollPane scrollPane = new JScrollPane(); scrollPane.setBorder(null); panel_1.add(scrollPane, "cell 2 2,grow"); scrollPane.setViewportView(lbl_refDbFiles); panel_1.add(lbl_refDbMetadata, "cell 2 3"); JButton btnNewDatabase = new JButton("New database..."); panel_1.add(btnNewDatabase, "cell 0 4"); btnNewDatabase.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { newDatabaseButton(); } }); } { JPanel panel_Step2 = new JPanel(); contentPanel.add(panel_Step2, "card_step2"); panel_Step2.setLayout(new BorderLayout(0, 0)); JLabel lblTitle = new JLabel("STEP 2 - Query (the \"unknown\")"); panel_Step2.add(lblTitle, BorderLayout.NORTH); lblTitle.setHorizontalAlignment(SwingConstants.CENTER); lblTitle.setFont(new Font("Tahoma", Font.PLAIN, 18)); JPanel panel = new JPanel(); panel.setBorder(new TitledBorder(UIManager.getBorder("TitledBorder.border"), "Query", TitledBorder.LEADING, TitledBorder.TOP, null, null)); panel_Step2.add(panel, BorderLayout.CENTER); panel.setLayout( new MigLayout("", "[160px][grow]", "[25px][grow,top][25px][grow,top][25px][grow,top][grow]")); ButtonGroup queryButtonGroup = new ButtonGroup(); queryButtonGroup.add(radio_queryFile); radio_queryFile.setFont(new Font("Tahoma", Font.PLAIN, 13)); panel.add(radio_queryFile, "cell 0 0"); lbl_queryFile.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { radio_queryFile.setSelected(true); } }); panel.add(lbl_queryFile, "flowy,cell 1 0"); JButton btnSelectFile = new JButton("Select File..."); btnSelectFile.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { selectFileButton(); } }); panel.add(btnSelectFile, "cell 1 0"); JLabel lblIumageOrVideo = new JLabel("Select an image or video in the local machine."); panel.add(lblIumageOrVideo, "cell 1 1"); queryButtonGroup.add(radio_queryUrl); radio_queryUrl.setFont(new Font("Tahoma", Font.PLAIN, 13)); panel.add(radio_queryUrl, "cell 0 2"); txt_queryUrl.addKeyListener(new KeyAdapter() { @Override public void keyReleased(KeyEvent e) { radio_queryUrl.setSelected(true); } }); txt_queryUrl.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { radio_queryUrl.setSelected(true); } }); txt_queryUrl.addFocusListener(new FocusAdapter() { @Override public void focusGained(FocusEvent e) { radio_queryUrl.setSelected(true); } }); txt_queryUrl.setText("http://"); panel.add(txt_queryUrl, "flowy,cell 1 2"); txt_queryUrl.setColumns(50); JLabel lblUrlToA = new JLabel( "<html>Enter the URL to download an image or video.<br>You can use a URL like: http://www.youtube.com/watch?v=... </html>"); panel.add(lblUrlToA, "flowy,cell 1 3"); queryButtonGroup.add(radio_queryDb); radio_queryDb.setFont(new Font("Tahoma", Font.PLAIN, 13)); panel.add(radio_queryDb, "cell 0 4"); comboBox_queryDb.setMaximumRowCount(12); comboBox_queryDb.setPreferredSize(new Dimension(100, 20)); comboBox_queryDb.setMinimumSize(new Dimension(100, 20)); comboBox_queryDb.addPropertyChangeListener(new PropertyChangeListener() { public void propertyChange(PropertyChangeEvent evt) { if (comboBox_queryDb.getSelectedIndex() > 0) radio_queryDb.setSelected(true); updateQueryDbDetail(); } }); comboBox_queryDb.addKeyListener(new KeyAdapter() { @Override public void keyReleased(KeyEvent e) { if (comboBox_queryDb.getSelectedIndex() > 0) radio_queryDb.setSelected(true); updateQueryDbDetail(); } }); panel.add(comboBox_queryDb, "flowx,cell 1 4"); panel.add(lbl_queryDb, "cell 1 4"); JLabel lblPleaseNopteThe = new JLabel("<html>A search is run for each video in the database.</html>"); panel.add(lblPleaseNopteThe, "cell 1 5"); } { JPanel panel_Step3 = new JPanel(); contentPanel.add(panel_Step3, "card_step3"); panel_Step3.setLayout(new BorderLayout(0, 0)); JLabel lblTitle = new JLabel("STEP 3 - Search Options"); lblTitle.setFont(new Font("Tahoma", Font.PLAIN, 18)); lblTitle.setHorizontalAlignment(SwingConstants.CENTER); panel_Step3.add(lblTitle, BorderLayout.NORTH); JPanel panel2 = new JPanel(); panel2.setLayout(new FlowLayout()); panel_Step3.add(panel2, BorderLayout.CENTER); JPanel panel = new JPanel(); panel2.add(panel); panel.setBorder(new TitledBorder(UIManager.getBorder("TitledBorder.border"), "Basic Options", TitledBorder.LEADING, TitledBorder.TOP, null, null)); panel.setLayout(new MigLayout("gapy 5px", "[30px][101px]", "[][][][][][][20px]")); ButtonGroup buttonGroup = new ButtonGroup(); buttonGroup.add(radio_searchByGlobal); radio_searchByGlobal.setFont(new Font("Tahoma", Font.PLAIN, 13)); radio_searchByGlobal.setSelected(true); panel.add(radio_searchByGlobal, "cell 0 0 2 1,alignx left,aligny top"); JLabel lblNewLabel_2 = new JLabel( "Detects most of the copies that are visually alike to the original."); panel.add(lblNewLabel_2, "cell 1 1"); JButton btnOptions = new JButton("Advanced Options..."); btnOptions.setEnabled(false); panel.add(btnOptions, "cell 1 2"); buttonGroup.add(radio_searchByLocal); radio_searchByLocal.setFont(new Font("Tahoma", Font.PLAIN, 13)); panel.add(radio_searchByLocal, "cell 0 4 2 1,alignx left,aligny top"); JLabel lblNewLabel_3 = new JLabel( "Requires more resources (disk space, search time, memory) but can detect more copies."); panel.add(lblNewLabel_3, "cell 1 5"); JButton btnOptions_1 = new JButton("Advanced Options..."); btnOptions_1.setEnabled(false); panel.add(btnOptions_1, "cell 1 6"); } { JPanel panel_Step4 = new JPanel(); contentPanel.add(panel_Step4, "card_step4"); panel_Step4.setLayout(new BorderLayout(0, 0)); JLabel lblTitle = new JLabel("STEP 4 - Search"); lblTitle.setHorizontalAlignment(SwingConstants.CENTER); lblTitle.setFont(new Font("Tahoma", Font.PLAIN, 18)); panel_Step4.add(lblTitle, BorderLayout.NORTH); JScrollPane scrollPane = new JScrollPane(); panel_Step4.add(scrollPane, BorderLayout.CENTER); textConsole.setFont(new Font("Monospaced", Font.PLAIN, 11)); textConsole.setForeground(Color.WHITE); textConsole.setBackground(Color.BLACK); textConsole.setEditable(false); textConsole.setCursor(new Cursor(Cursor.TEXT_CURSOR)); textConsole.setText( "Press 'Next' button to start the search...\nNote: Depending on the selected options, the search may take up to several hours."); scrollPane.setViewportView(textConsole); JPanel panel = new JPanel(); panel_Step4.add(panel, BorderLayout.SOUTH); panel.setLayout(new GridLayout(0, 1, 0, 0)); JSeparator separator = new JSeparator(); separator.setPreferredSize(new Dimension(0, 1)); panel.add(separator); progressBar.setStringPainted(true); progressBar.setPreferredSize(new Dimension(350, 20)); panel.add(progressBar); lblProgress.setHorizontalAlignment(SwingConstants.CENTER); lblProgress.setFont(new Font("Tahoma", Font.PLAIN, 14)); panel.add(lblProgress); } { JPanel panel_Step5 = new JPanel(); contentPanel.add(panel_Step5, "card_step5"); panel_Step5.setLayout(new BorderLayout(0, 0)); JLabel lblTitle = new JLabel("STEP 5 - Results"); lblTitle.setHorizontalAlignment(SwingConstants.CENTER); lblTitle.setFont(new Font("Tahoma", Font.PLAIN, 18)); panel_Step5.add(lblTitle, BorderLayout.NORTH); JScrollPane scrollPane = new JScrollPane(); panel_Step5.add(scrollPane, BorderLayout.CENTER); scrollPane.setViewportView(panelResults); panelResults.setLayout(new MigLayout("gapy 10, gapx 20", "[120px,center][150px,center,grow][150px,center,grow]", "[25px][]")); } { JPanel buttonPane = new JPanel(); buttonPane.setLayout(new FlowLayout(FlowLayout.RIGHT)); getContentPane().add(buttonPane, BorderLayout.SOUTH); { JButton prevButton = new JButton("Previous"); prevButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { previousButton(); } }); prevButton.setActionCommand("Previous"); buttonPane.add(prevButton); } { JButton okButton = new JButton("Next"); okButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { nextButton(); } }); okButton.setActionCommand("OK"); buttonPane.add(okButton); getRootPane().setDefaultButton(okButton); } { JButton cancelButton = new JButton("Cancel"); cancelButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { cancelButton(); } }); cancelButton.setActionCommand("Cancel"); buttonPane.add(cancelButton); } } this.addWindowListener(new WindowAdapter() { @Override public void windowClosed(WindowEvent e) { closeWindow(); } }); updateDatabases(null); }
From source file:org.p_vcd.ui.VcdDialog.java
private void drawDetectionResult() { panelResults.removeAll();/* ww w .j a v a2 s . co m*/ if (this.resultDetections == null || this.resultDetections.size() == 0) { JLabel ll1 = new JLabel("Search did not produce any result!"); ll1.setFont(new Font("Tahoma", Font.PLAIN, 14)); JLabel ll2 = new JLabel("Press the 'Previous' button and try with other parameters."); ll2.setFont(new Font("Tahoma", Font.PLAIN, 14)); panelResults.add(ll1, "cell 0 0 3 1"); panelResults.add(ll2, "cell 0 1 3 1"); } else { JLabel lblQ = new JLabel("Query Video"); lblQ.setFont(new Font("Tahoma", Font.BOLD, 13)); JLabel lblR = new JLabel("Original Video"); lblR.setFont(new Font("Tahoma", Font.BOLD, 13)); panelResults.add(lblQ, "cell 1 0"); panelResults.add(lblR, "cell 2 0"); for (int i = 0; i < this.resultDetections.size(); ++i) { VideoCopy vc = this.resultDetections.get(i); final int rowPos = i + 1; JButton butt = new JButton("<html><body style='width:100%;text-align:center'>Watch Video Copy<br>(" + vc.getLengthTxt() + " length)"); // butt.setHorizontalAlignment(SwingConstants.CENTER); butt.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { launchCopy("" + rowPos); } }); JLabel timQ = new JLabel("<html><body style='width:100%;text-align:center'>" + vc.getVideoQ().getFilename() + "<br><i>" + vc.getFromQtxt() + " - " + vc.getToQtxt()); JLabel timR = new JLabel("<html><body style='width:100%;text-align:center'>" + vc.getVideoR().getFilename() + "<br><i>" + vc.getFromRtxt() + " - " + vc.getToRtxt()); panelResults.add(butt, "cell 0 " + rowPos); panelResults.add(timQ, "cell 1 " + rowPos); panelResults.add(timR, "cell 2 " + rowPos); } } panelResults.validate(); currentStep = 5; CardLayout cl = (CardLayout) contentPanel.getLayout(); cl.show(contentPanel, "card_step" + currentStep); }
From source file:org.rapidcontext.app.ui.ControlPanel.java
/** * Initializes the panel UI./* ww w .ja v a 2 s.c om*/ */ private void initialize() { Rectangle bounds = new Rectangle(); GridBagConstraints c; JLabel label; Font font; Properties info; String str; // Set system UI looks if (SystemUtils.IS_OS_MAC_OSX || SystemUtils.IS_OS_WINDOWS) { try { UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); } catch (Exception ignore) { // Ah well... at least we tried. } } // Set title, menu & layout setDefaultCloseOperation(EXIT_ON_CLOSE); setTitle("RapidContext Server"); setMenuBar(menuBar); initializeMenu(); getContentPane().setLayout(new GridBagLayout()); try { logotype = ImageIO.read(getClass().getResource("logotype.png")); Image img = ImageIO.read(getClass().getResource("logotype-icon-256x256.png")); setIconImage(img); if (SystemUtils.IS_OS_MAC_OSX) { MacApplication.get().setDockIconImage(img); } } catch (Exception ignore) { // Again, we only do our best effort here } // Add logotype c = new GridBagConstraints(); c.gridheight = 5; c.insets = new Insets(6, 15, 10, 10); c.anchor = GridBagConstraints.NORTHWEST; Image small = logotype.getScaledInstance(128, 128, Image.SCALE_SMOOTH); getContentPane().add(new JLabel(new ImageIcon(small)), c); // Add link label c = new GridBagConstraints(); c.gridx = 1; c.insets = new Insets(10, 10, 2, 10); c.anchor = GridBagConstraints.WEST; getContentPane().add(new JLabel("Server URL:"), c); serverLink.setText("http://localhost:" + server.port + "/"); serverLink.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { try { AppUtils.openURL(serverLink.getText()); } catch (Exception e) { error(e.getMessage()); } } }); c = new GridBagConstraints(); c.gridx = 2; c.weightx = 1.0; c.insets = new Insets(10, 0, 2, 10); c.anchor = GridBagConstraints.WEST; getContentPane().add(serverLink, c); // Add login info label label = new JLabel("Login as 'admin' on a new server."); font = label.getFont(); font = font.deriveFont(Font.ITALIC, font.getSize() - 2); label.setFont(font); c = new GridBagConstraints(); c.gridx = 2; c.gridy = 1; c.gridwidth = 2; c.insets = new Insets(0, 0, 6, 10); c.anchor = GridBagConstraints.WEST; getContentPane().add(label, c); // Add status label c = new GridBagConstraints(); c.gridx = 1; c.gridy = 2; c.insets = new Insets(0, 10, 6, 10); c.anchor = GridBagConstraints.WEST; getContentPane().add(new JLabel("Status:"), c); c = new GridBagConstraints(); c.gridx = 2; c.gridy = 2; c.insets = new Insets(0, 0, 6, 10); c.anchor = GridBagConstraints.WEST; getContentPane().add(statusLabel, c); // Add version label c = new GridBagConstraints(); c.gridx = 1; c.gridy = 3; c.insets = new Insets(0, 10, 6, 10); c.anchor = GridBagConstraints.WEST; getContentPane().add(new JLabel("Version:"), c); c = new GridBagConstraints(); c.gridx = 2; c.gridy = 3; c.insets = new Insets(0, 0, 6, 10); c.anchor = GridBagConstraints.WEST; info = Main.buildInfo(); str = info.getProperty("build.version") + " (built " + info.getProperty("build.date") + ")"; getContentPane().add(new JLabel(str), c); // Add buttons startButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { start(); } }); c = new GridBagConstraints(); c.gridx = 1; c.gridy = 4; c.weighty = 1.0; c.insets = new Insets(0, 10, 10, 10); c.anchor = GridBagConstraints.SOUTH; getContentPane().add(startButton, c); stopButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { stop(); } }); c = new GridBagConstraints(); c.gridx = 2; c.gridy = 4; c.weighty = 1.0; c.insets = new Insets(0, 0, 10, 0); c.anchor = GridBagConstraints.SOUTHWEST; getContentPane().add(stopButton, c); // Set size & position pack(); bounds = this.getBounds(); bounds.width = 470; bounds.x = 100; bounds.y = 100; setBounds(bounds); }
From source file:org.rdv.datapanel.AbstractDataPanel.java
JComponent getDescriptionComponent() { JLabel descriptionLabel = new JLabel(description); descriptionLabel.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 10)); descriptionLabel.setFont(descriptionLabel.getFont().deriveFont(Font.BOLD)); descriptionLabel.setForeground(Color.white); return descriptionLabel; }
From source file:org.revager.gui.findings_list.FindingsListFrame.java
private void createAttPanel() { GridLayout grid = new GridLayout(4, 1); grid.setVgap(8);/*w ww . j a va 2s. c o m*/ JPanel attendeeButtons = new JPanel(grid); addResiAtt = GUITools.newImageButton(); addResiAtt.setIcon(Data.getInstance().getIcon("addResiAtt_25x25_0.png")); addResiAtt.setRolloverIcon(Data.getInstance().getIcon("addResiAtt_25x25.png")); addResiAtt.setToolTipText(translate("Add Attendee from the Attendee Pool")); addResiAtt.addActionListener(ActionRegistry.getInstance().get(AddResiAttToProtAction.class.getName())); attendeeButtons.add(addResiAtt); JButton addAttendee = GUITools.newImageButton(); addAttendee.setIcon(Data.getInstance().getIcon("addAttendee_25x25_0.png")); addAttendee.setRolloverIcon(Data.getInstance().getIcon("addAttendee_25x25.png")); addAttendee.setToolTipText(translate("Add Attendee")); addAttendee.addActionListener(ActionRegistry.getInstance().get(AddAttToProtAction.class.getName())); attendeeButtons.add(addAttendee); removeAttendee = GUITools.newImageButton(); removeAttendee.setIcon(Data.getInstance().getIcon("removeAttendee_25x25_0.png")); removeAttendee.setRolloverIcon(Data.getInstance().getIcon("removeAttendee_25x25.png")); removeAttendee.setToolTipText(translate("Remove Attendee")); removeAttendee.addActionListener(ActionRegistry.getInstance().get(RemAttFromProtAction.class.getName())); attendeeButtons.add(removeAttendee); editAttendee = GUITools.newImageButton(); editAttendee.setIcon(Data.getInstance().getIcon("editAttendee_25x25_0.png")); editAttendee.setRolloverIcon(Data.getInstance().getIcon("editAttendee_25x25.png")); editAttendee.setToolTipText(translate("Edit Attendee")); editAttendee.addActionListener(ActionRegistry.getInstance().get(EditAttFromProtAction.class.getName())); attendeeButtons.add(editAttendee); editAttendee.setEnabled(false); removeAttendee.setEnabled(false); presentAttTable.setRowHeight(55); presentAttTable.getColumnModel().getColumn(0).setMaxWidth(55); presentAttTable.setShowHorizontalLines(false); presentAttTable.setShowVerticalLines(true); presentAttTable.setShowGrid(true); presentAttTable.addMouseListener(new MouseListener() { @Override public void mouseClicked(MouseEvent e) { if (e.getClickCount() == 2) { ActionRegistry.getInstance().get(EditAttFromProtAction.class.getName()).actionPerformed(null); } } @Override public void mouseEntered(MouseEvent e) { } @Override public void mouseExited(MouseEvent e) { } @Override public void mousePressed(MouseEvent e) { } @Override public void mouseReleased(MouseEvent e) { } }); TableCellRenderer renderer = (table, value, isSelected, hasFocus, row, column) -> { JLabel label = new JLabel((String) value); label.setOpaque(true); label.setBorder(new EmptyBorder(5, 5, 5, 5)); label.setFont(UI.VERY_LARGE_FONT); if (isSelected) { label.setBackground(presentAttTable.getSelectionBackground()); } else { if (row % 2 == 0) { label.setBackground(UI.TABLE_ALT_COLOR); } else { label.setBackground(presentAttTable.getBackground()); } } return label; }; for (int i = 1; i <= 4; i++) { presentAttTable.getColumnModel().getColumn(i).setCellRenderer(renderer); } TableColumn col = presentAttTable.getColumnModel().getColumn(0); col.setCellRenderer((table, value, isSelected, hasFocus, row, column) -> { JPanel localPnl = new JPanel(); localPnl.add(new JLabel(Data.getInstance().getIcon("attendee_40x40.png"))); if (isSelected) { localPnl.setBackground(presentAttTable.getSelectionBackground()); } else { if (row % 2 == 0) { localPnl.setBackground(UI.TABLE_ALT_COLOR); } else { localPnl.setBackground(presentAttTable.getBackground()); } } return localPnl; }); presentAttTable.addMouseListener(new MouseListener() { @Override public void mouseClicked(MouseEvent e) { updateAttButtons(); } @Override public void mouseEntered(MouseEvent e) { } @Override public void mouseExited(MouseEvent e) { } @Override public void mousePressed(MouseEvent e) { } @Override public void mouseReleased(MouseEvent e) { } }); scrllP = GUITools.setIntoScrollPane(presentAttTable); scrllP.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); scrllP.setToolTipText(translate("Add Attendee to Meeting")); scrllP.addMouseListener(new MouseListener() { @Override public void mouseClicked(MouseEvent e) { if (isAddResiAttPossible()) { ActionRegistry.getInstance().get(AddResiAttToProtAction.class.getName()).actionPerformed(null); } else { ActionRegistry.getInstance().get(AddAttToProtAction.class.getName()).actionPerformed(null); } } @Override public void mouseEntered(MouseEvent e) { } @Override public void mouseExited(MouseEvent e) { } @Override public void mousePressed(MouseEvent e) { } @Override public void mouseReleased(MouseEvent e) { } }); JLabel labelAttendees = new JLabel(translate("Attendees of the current meeting:")); labelAttendees.setFont(UI.HUGE_FONT_BOLD); GUITools.addComponent(attPanel, gbl, labelAttendees, 0, 0, 2, 1, 1.0, 0.0, 20, 20, 0, 20, GridBagConstraints.BOTH, GridBagConstraints.NORTHWEST); GUITools.addComponent(attPanel, gbl, scrllP, 0, 1, 1, 1, 1.0, 1.0, 20, 20, 0, 20, GridBagConstraints.BOTH, GridBagConstraints.NORTHWEST); GUITools.addComponent(attPanel, gbl, attendeeButtons, 1, 1, 1, 1, 0, 0, 20, 0, 20, 20, GridBagConstraints.NONE, GridBagConstraints.NORTHWEST); }
From source file:org.revager.gui.findings_list.FindingsListFrame.java
private void createImpPanel() { JLabel impLbl = new JLabel(translate("General impression of the product:")); impLbl.setFont(UI.VERY_LARGE_FONT_BOLD); impTxtArea = new JTextArea(); impTxtArea.setFont(UI.VERY_LARGE_FONT); impTxtArea.addKeyListener(updateListener); impTxtArea.addKeyListener(tabKeyListener); impTxtArea.setText(revMgmt.getImpression().trim()); impScrllPn = GUITools.setIntoScrllPn(impTxtArea); GUITools.scrollToTop(impScrllPn);/*from ww w. j a va 2s. c o m*/ GUITools.addComponent(tabGenImp, gbl, impLbl, 0, 1, 2, 1, 0, 0, 20, 10, 0, 10, GridBagConstraints.NONE, GridBagConstraints.NORTHWEST); GUITools.addComponent(tabGenImp, gbl, impScrllPn, 0, 2, 2, 1, 1.0, 1.0, 5, 10, 0, 10, GridBagConstraints.BOTH, GridBagConstraints.NORTHWEST); tabGenImp.setBorder(new EmptyBorder(0, 10, 20, 10)); }
From source file:org.revager.gui.findings_list.FindingsListFrame.java
private void createBottomOrgPanel() { JLabel locationLbl = new JLabel(translate("Location:")); locationLbl.setFont(UI.VERY_LARGE_FONT_BOLD); JLabel dateLbl = new JLabel(translate("Date:")); dateLbl.setFont(UI.VERY_LARGE_FONT_BOLD); JLabel beginLbl = new JLabel(translate("Period of time:")); beginLbl.setFont(UI.VERY_LARGE_FONT_BOLD); JLabel tillLabel = new JLabel(translate("to")); tillLabel.setFont(UI.VERY_LARGE_FONT_BOLD); clockLabel.setFont(UI.VERY_LARGE_FONT_BOLD); dateTxtFld = new ObservingTextField(); dateTxtFld.setFont(UI.VERY_LARGE_FONT); dateTxtFld.setFocusable(false);/*w ww .j ava2 s. c om*/ dateTxtFld.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); dateTxtFld.setPreferredSize(new Dimension(190, (int) dateTxtFld.getPreferredSize().getHeight())); dateTxtFld.setMinimumSize(dateTxtFld.getPreferredSize()); dateTxtFld.addMouseListener(new MouseListener() { @Override public void mouseClicked(MouseEvent e) { // instantiate the DatePicker DatePicker dp = new DatePicker(UI.getInstance().getProtocolFrame(), UI.getInstance().getProtocolFrame().getDateTxtFld()); // previously selected date Date selectedDate = dp.parseDate(UI.getInstance().getProtocolFrame().getDateTxtFld().getText()); dp.setSelectedDate(selectedDate); dp.start(UI.getInstance().getProtocolFrame().getDateTxtFld()); } @Override public void mouseEntered(MouseEvent e) { } @Override public void mouseExited(MouseEvent e) { } @Override public void mousePressed(MouseEvent e) { } @Override public void mouseReleased(MouseEvent e) { } }); dateTxtFld.addKeyListener(updateListener); /* * creating spinner panel */ beginMSpinner = new JSpinner(new RotateSpinnerNumberModel(00, 00, 59, 1)); beginHSpinner = new JSpinner(new RotateSpinnerNumberModel(00, 00, 23, 1)); endMSpinner = new JSpinner(new RotateSpinnerNumberModel(00, 00, 59, 1)); endHSpinner = new JSpinner(new RotateSpinnerNumberModel(00, 00, 23, 1)); beginMSpinner.setFont(UI.VERY_LARGE_FONT); beginHSpinner.setFont(UI.VERY_LARGE_FONT); endHSpinner.setFont(UI.VERY_LARGE_FONT); endMSpinner.setFont(UI.VERY_LARGE_FONT); beginMSpinner.addChangeListener(spinnerChangeListener); beginHSpinner.addChangeListener(spinnerChangeListener); endHSpinner.addChangeListener(spinnerChangeListener); endMSpinner.addChangeListener(spinnerChangeListener); locationTxtFld = new JTextField(); locationTxtFld.setFont(UI.VERY_LARGE_FONT); /* * Hide border if the application runs on Mac OS X */ boolean hideBorder = UI.getInstance().getPlatform() == UI.Platform.MAC; GUITools.formatSpinner(endHSpinner, hideBorder); GUITools.formatSpinner(endMSpinner, hideBorder); GUITools.formatSpinner(beginHSpinner, hideBorder); GUITools.formatSpinner(beginMSpinner, hideBorder); // TODO: In some cases 'currentProt.getDate()' returns null. dateF.setTimeZone(currentProt.getDate().getTimeZone()); dateTxtFld.setText(dateF.format(currentProt.getDate().getTime())); int beginHours = currentProt.getStart().get(Calendar.HOUR_OF_DAY); beginMSpinner.setValue(currentProt.getStart().get(Calendar.MINUTE)); beginHSpinner.setValue(beginHours); int endHours = currentProt.getEnd().get(Calendar.HOUR_OF_DAY); endMSpinner.setValue(currentProt.getEnd().get(Calendar.MINUTE)); endHSpinner.setValue(endHours); /* * Correct the leading zero's */ if ((Integer) beginMSpinner.getValue() == 0) { ((NumberEditor) beginMSpinner.getEditor()).getTextField().setText("00"); } if ((Integer) beginHSpinner.getValue() == 0) { ((NumberEditor) beginHSpinner.getEditor()).getTextField().setText("00"); } if ((Integer) endMSpinner.getValue() == 0) { ((NumberEditor) endMSpinner.getEditor()).getTextField().setText("00"); } if ((Integer) endHSpinner.getValue() == 0) { ((NumberEditor) endHSpinner.getEditor()).getTextField().setText("00"); } locationTxtFld.setText(currentProt.getLocation().trim()); JPanel spinnerPanel = new JPanel(gbl); spinnerPanel.setOpaque(false); JLabel labelDoubleDot1 = new JLabel(":"); labelDoubleDot1.setFont(UI.VERY_LARGE_FONT_BOLD); JLabel labelDoubleDot2 = new JLabel(":"); labelDoubleDot2.setFont(UI.VERY_LARGE_FONT_BOLD); GUITools.addComponent(spinnerPanel, gbl, beginHSpinner, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, GridBagConstraints.VERTICAL, GridBagConstraints.NORTHWEST); GUITools.addComponent(spinnerPanel, gbl, labelDoubleDot1, 1, 0, 1, 1, 0, 0, 0, 5, 0, 0, GridBagConstraints.VERTICAL, GridBagConstraints.CENTER); GUITools.addComponent(spinnerPanel, gbl, beginMSpinner, 2, 0, 1, 1, 0, 0, 0, 5, 0, 0, GridBagConstraints.VERTICAL, GridBagConstraints.NORTHWEST); GUITools.addComponent(spinnerPanel, gbl, tillLabel, 3, 0, 1, 1, 1.0, 0, 0, 10, 0, 10, GridBagConstraints.VERTICAL, GridBagConstraints.CENTER); GUITools.addComponent(spinnerPanel, gbl, endHSpinner, 4, 0, 1, 1, 0, 0, 0, 0, 0, 0, GridBagConstraints.VERTICAL, GridBagConstraints.NORTHEAST); GUITools.addComponent(spinnerPanel, gbl, labelDoubleDot2, 5, 0, 1, 1, 0, 0, 0, 5, 0, 0, GridBagConstraints.VERTICAL, GridBagConstraints.CENTER); GUITools.addComponent(spinnerPanel, gbl, endMSpinner, 6, 0, 1, 1, 0, 0, 0, 5, 0, 0, GridBagConstraints.VERTICAL, GridBagConstraints.NORTHEAST); /* * adding created components to orgpanel */ GUITools.addComponent(bottomOrgPanel, gbl, dateLbl, 2, 0, 1, 1, 0.0, 1.0, 10, 20, 0, 0, GridBagConstraints.NONE, GridBagConstraints.WEST); GUITools.addComponent(bottomOrgPanel, gbl, dateTxtFld, 3, 0, 1, 1, 0.0, 1.0, 10, 5, 0, 0, GridBagConstraints.HORIZONTAL, GridBagConstraints.WEST); GUITools.addComponent(bottomOrgPanel, gbl, locationLbl, 0, 0, 1, 1, 0.0, 1.0, 10, 20, 0, 0, GridBagConstraints.NONE, GridBagConstraints.WEST); GUITools.addComponent(bottomOrgPanel, gbl, locationTxtFld, 1, 0, 1, 1, 1.0, 1.0, 10, 5, 0, 10, GridBagConstraints.HORIZONTAL, GridBagConstraints.WEST); GUITools.addComponent(bottomOrgPanel, gbl, beginLbl, 5, 0, 1, 1, 0.0, 1.0, 10, 30, 0, 0, GridBagConstraints.NONE, GridBagConstraints.EAST); GUITools.addComponent(bottomOrgPanel, gbl, spinnerPanel, 6, 0, 1, 1, 0.0, 1.0, 10, 5, 0, 25, GridBagConstraints.VERTICAL, GridBagConstraints.WEST); updateAttButtons(); }
From source file:org.revager.gui.findings_list.FindingsListFrame.java
private void createCommAndRatePanel() { JLabel recLbl = new JLabel(translate("Final recommendation for the product:")); recLbl.setFont(UI.VERY_LARGE_FONT_BOLD); JLabel meetCommLbl = new JLabel(translate("Comments on the meeting:")); meetCommLbl.setFont(UI.VERY_LARGE_FONT_BOLD); JLabel protCommLbl = new JLabel(translate("Comments on the list of findings:")); protCommLbl.setFont(UI.VERY_LARGE_FONT_BOLD); meetCommTxtArea = new JTextArea(); meetCommTxtArea.setRows(4);// w w w. j av a 2 s.c om meetCommTxtArea.setFont(UI.VERY_LARGE_FONT); protCommTxtArea = new JTextArea(); protCommTxtArea.setRows(4); protCommTxtArea.setFont(UI.VERY_LARGE_FONT); recBx = new JComboBox<>(); recBx.setEditable(true); recBx.setFont(UI.VERY_LARGE_FONT); /* * adding focus and tab listeners to TextAreas */ meetCommTxtArea.addKeyListener(updateListener); meetCommTxtArea.addKeyListener(tabKeyListener); protCommTxtArea.addKeyListener(updateListener); protCommTxtArea.addKeyListener(tabKeyListener); for (String rec : Data.getDefaultRecommendations()) { recBx.addItem(rec); } recBx.setSelectedIndex(0); recBx.addItemListener(itemListener); recBx.setSelectedItem(revMgmt.getRecommendation().trim()); meetCommTxtArea.setText(Application.getInstance().getMeetingMgmt().getMeetingComment(currentMeet).trim()); protCommTxtArea.setText(protMgmt.getProtocolComment(currentProt).trim()); JScrollPane meetCommScrllPn = GUITools.setIntoScrllPn(meetCommTxtArea); meetCommScrllPn.setMinimumSize(meetCommScrllPn.getPreferredSize()); GUITools.scrollToTop(meetCommScrllPn); protCommScrllPn = GUITools.setIntoScrllPn(protCommTxtArea); protCommScrllPn.setMinimumSize(protCommScrllPn.getPreferredSize()); GUITools.scrollToTop(protCommScrllPn); GUITools.addComponent(tabPanelCommAndRec, gbl, recLbl, 0, 3, 2, 1, 0.0, 0.0, 20, 10, 0, 10, GridBagConstraints.NONE, GridBagConstraints.NORTHWEST); GUITools.addComponent(tabPanelCommAndRec, gbl, recBx, 0, 4, 2, 1, 1.0, 0.0, 5, 10, 0, 10, GridBagConstraints.HORIZONTAL, GridBagConstraints.NORTHWEST); GUITools.addComponent(tabPanelCommAndRec, gbl, meetCommLbl, 0, 5, 1, 1, 1.0, 0.0, 25, 10, 0, 10, GridBagConstraints.NONE, GridBagConstraints.NORTHWEST); GUITools.addComponent(tabPanelCommAndRec, gbl, meetCommScrllPn, 0, 6, 1, 1, 1.0, 1.0, 5, 10, 0, 10, GridBagConstraints.BOTH, GridBagConstraints.NORTHWEST); GUITools.addComponent(tabPanelCommAndRec, gbl, protCommLbl, 1, 5, 1, 1, 1.0, 0.0, 25, 10, 0, 10, GridBagConstraints.NONE, GridBagConstraints.NORTHWEST); GUITools.addComponent(tabPanelCommAndRec, gbl, protCommScrllPn, 1, 6, 1, 1, 1.0, 1.0, 5, 10, 0, 10, GridBagConstraints.BOTH, GridBagConstraints.NORTHWEST); tabPanelCommAndRec.setBorder(new EmptyBorder(0, 10, 20, 10)); }
From source file:org.spottedplaid.ui.Mainframe.java
/** * Create the frame.// ww w.j a v a2 s. c om * * @param _Sqliteops the _ sqliteops * @param _Crypto the _ crypto */ public Mainframe(SQliteOps _Sqliteops, Crypto _Crypto) { l_sqliteops = _Sqliteops; l_crypto = _Crypto; setTitle("The Password Saver - Management"); setResizable(false); setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); setBounds(100, 100, 982, 656); JMenuBar menuBar = new JMenuBar(); setJMenuBar(menuBar); JMenu mnFile = new JMenu("File"); menuBar.add(mnFile); JMenuItem mntmExit = new JMenuItem("Exit"); mntmExit.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { System.exit(0); } }); mnFile.add(mntmExit); JMenu mnTools = new JMenu("Tools"); menuBar.add(mnTools); JMenuItem mntmChgpwd = new JMenuItem("Change Passphrase"); mntmChgpwd.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { Changepwd changePwd = new Changepwd(l_crypto, l_sqliteops); changePwd.setVisible(true); } }); mnTools.add(mntmChgpwd); JMenuItem mntmExpirationReport = new JMenuItem("Expiration Report"); mntmExpirationReport.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { DbRecord dbRecExp = new DbRecord(); dbRecExp.setType(Pwdtypes.S_EXP_RPT); ArrayList<String> arrData = l_sqliteops.getRecords(dbRecExp); String[] sRecord = new String[3]; String sData = ""; int iElement = 0; /// Cycle through the data, output to text file, and open in WordPad if (arrData != null && arrData.size() > 0) { try { String sFilename = "ExpirationReport.txt"; File fileExpRpt = new File(sFilename); BufferedWriter buffWriter = new BufferedWriter(new FileWriter(fileExpRpt)); buffWriter.write("URL/Application Challenge Expiration"); buffWriter.write("\n"); buffWriter.write("--------------------------------------------------------------"); buffWriter.write("\n"); for (int iCount = 0; iCount < arrData.size(); iCount++) { sData = arrData.get(iCount); System.out.println("DEBUG->sData [" + sData + "]"); StringTokenizer st = new StringTokenizer(sData, "|"); iElement = 0; while (st.hasMoreTokens()) { sRecord[iElement] = st.nextToken(); iElement++; } /// Define the padding for the output int iPadValue1 = 35 - sRecord[0].length(); if (iPadValue1 < 0) { iPadValue1 = 2; } int iPadValue2 = 55 - (35 + sRecord[1].length()); if (iPadValue2 < 0) { iPadValue2 = 2; } iPadValue1 += sRecord[1].length(); iPadValue2 += sRecord[2].length(); buffWriter.write(sRecord[0] + StringUtils.leftPad(sRecord[1], iPadValue1) + StringUtils.leftPad(sRecord[2], iPadValue2) + "\n"); buffWriter.write("\n"); } buffWriter.close(); /// Opens WordPad on Windows systems. This could be changed to use a property in order to work on a linux/unix/apple system ProcessBuilder pb = new ProcessBuilder("write.exe", sFilename); pb.start(); } catch (IOException ie) { System.out.println("Expiration Report IO Exception [" + ie.getMessage() + "]"); ie.printStackTrace(); } } else { JOptionPane.showMessageDialog(null, "No expiring records found"); } } }); mnTools.add(mntmExpirationReport); JMenuItem mntmViewLogs = new JMenuItem("View Logs"); mntmViewLogs.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { DbRecord dbRecLogs = new DbRecord(); dbRecLogs.setType(Pwdtypes.S_LOG_TYPE); ArrayList<String> arrData = l_sqliteops.getRecords(dbRecLogs); String[] sRecord = new String[3]; String sData = ""; String sTitle = "Display Data Changes"; String sDisplay = "Date Log Message"; sDisplay += "\n"; int iElement = 0; /// Cycle through the data, output to text file, and open in WordPad if (arrData != null) { for (int iCount = 0; iCount < arrData.size(); iCount++) { sData = arrData.get(iCount); System.out.println("DEBUG->sData [" + sData + "]"); StringTokenizer st = new StringTokenizer(sData, "|"); iElement = 0; while (st.hasMoreTokens()) { sRecord[iElement] = st.nextToken(); iElement++; } sDisplay += sRecord[2] + ":" + sRecord[1]; sDisplay += "\n"; } if (arrData.size() > 0) { JOptionPane.showMessageDialog(null, sDisplay, sTitle, JOptionPane.INFORMATION_MESSAGE); } } } }); mnTools.add(mntmViewLogs); contentPane = new JPanel(); contentPane.setBorder(new EmptyBorder(5, 5, 5, 5)); setContentPane(contentPane); JLabel lblThePasswordSaver = new JLabel("The Password Saver - Manage Passwords"); lblThePasswordSaver.setFont(new Font("Arial", Font.BOLD, 16)); lblThePasswordSaver.setHorizontalAlignment(SwingConstants.CENTER); JLabel lblUrlapplication = new JLabel("URL/Application"); jtxtApp = new JTextField(); jtxtApp.setColumns(10); JLabel lblDescription = new JLabel("Description"); jtxtDesc = new JTextField(); jtxtDesc.setColumns(10); /// Button - Add button for clients/apps JButton btnAdd = new JButton("Add"); btnAdd.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { if (FormValidation.verifyAppData(jtxtApp.getText().toString(), jtxtDesc.getText().toString()) < 0) { JOptionPane.showMessageDialog(null, "URL/Application and Description are required"); } else { dbRec = new DbRecord(); dbRec.setType(Pwdtypes.S_CLIENT_TYPE); dbRec.setClientName(jtxtApp.getText().toString()); dbRec.setClientDesc(jtxtDesc.getText().toString()); int l_iClientId = l_sqliteops.insertRecord(dbRec); if (l_iClientId <= 0) { JOptionPane.showMessageDialog(null, "Insert record failed [" + dbRec.getResult() + "]"); } else { dbRec.setClientId(l_iClientId); addToTable(); } } } }); /// Buttons - Replace button for clients/apps btnReplace = new JButton("Replace"); btnReplace.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { if (iClientId <= 0) { JOptionPane.showMessageDialog(null, "Update record warning: Please select record to continue"); return; } dbRec = new DbRecord(); dbRec.setType(Pwdtypes.S_CLIENT_TYPE); dbRec.setClientId(iClientId); dbRec.setClientName(jtxtApp.getText().toString()); dbRec.setClientDesc(jtxtDesc.getText().toString()); if (l_sqliteops.updateRecord(dbRec) < 0) { JOptionPane.showMessageDialog(null, "Update record failed [" + dbRec.getResult() + "]"); } else { int iRow = jtabApps.getSelectedRow(); jtabApps.setValueAt(jtxtApp.getText().toString(), iRow, 1); jtabApps.setValueAt(jtxtDesc.getText().toString(), iRow, 2); clearFields(); } } }); btnReplace.setEnabled(false); /// Button - Delete button for clients/apps btnDelete = new JButton("Delete"); btnDelete.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { if (iClientId <= 0) { JOptionPane.showMessageDialog(null, "Delete record failed: Please select a record then click Delete"); return; } dbRec = new DbRecord(); dbRec.setType("clients"); dbRec.setClientId(iClientId); dbRec.setDelCreds(0); if (chkDelAssoc.isSelected()) { dbRec.setDelCreds(1); } if (l_sqliteops.deleteRecord(dbRec) < 0) { JOptionPane.showMessageDialog(null, "Delete record failed [" + dbRec.getResult() + "]"); } else { DefaultTableModel jtabModel = (DefaultTableModel) jtabApps.getModel(); jtabModel.removeRow(jtabApps.getSelectedRow()); if (chkDelAssoc.isSelected()) { DefaultTableModel model = (DefaultTableModel) jtabCreds.getModel(); model.setRowCount(0); } clearFields(); } } }); btnDelete.setEnabled(false); /// Buttons - Search button for clients/apps btnSearch = new JButton("Search"); btnSearch.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { dbRec = new DbRecord(); dbRec.setType(Pwdtypes.S_CLIENT_TYPE); dbRec.setClientName(jtxtApp.getText().toString()); dbRec.setClientDesc(jtxtDesc.getText().toString()); loadTable(dbRec); } }); btnClear = new JButton("Clear"); btnClear.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { clearFields(); } }); JScrollPane scrollPane = new JScrollPane(); scrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS); /// Begin section for credentials challenges/responses - text fields and buttons JLabel lblChallenge = new JLabel("Challenge"); JLabel lblResponse = new JLabel("Response"); jtxtChlng = new JTextField(); jtxtChlng.setColumns(10); jtxtRsp = new JTextField(); jtxtRsp.setColumns(10); /// Buttons - Add button for credentials btnCredAdd = new JButton("Add"); btnCredAdd.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { if (FormValidation.verifyCredData(jtxtChlng.getText().toString(), jtxtRsp.getText().toString()) < 0) { JOptionPane.showMessageDialog(null, "Challenge and Response are required"); } else { dbRec = new DbRecord(); dbRec.setType(Pwdtypes.S_CREDS_TYPE); dbRec.setClientId(iClientId); dbRec.setChallenge(jtxtChlng.getText().toString()); dbRec.setResponse(l_crypto.encrypt(jtxtRsp.getText().toString())); dbRec.setTrack(jcbTrack.getSelectedItem().toString()); /// Set the modify date if the track days are > 0 if (!jcbTrack.getSelectedItem().toString().equals("0")) { Calendar calNow = Calendar.getInstance(); SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/yyyy"); int iDaysToAdd = Integer.parseInt(jcbTrack.getSelectedItem().toString()); calNow.add(Calendar.DATE, iDaysToAdd); String sValue = sdf.format(calNow.getTime()); dbRec.setModifyDate(sValue); } int l_iClientId = l_sqliteops.insertRecord(dbRec); if (l_iClientId <= 0) { JOptionPane.showMessageDialog(null, "Insert record failed [" + dbRec.getResult() + "]"); } else { dbRec.setCredId(l_iClientId); addToCredsTable(); } } } }); /// Button - Replace button for credentials btnCredReplace = new JButton("Replace"); btnCredReplace.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { DbRecord dbRecLog = new DbRecord(); int iDaysToAdd = 0; Calendar calNow = Calendar.getInstance(); SimpleDateFormat sdf1 = new SimpleDateFormat("MM/dd/yyyy"); String sCurDate = sdf1.format(calNow.getTime()); String sValue = sDateModified; String sLogMsg = ""; StringBuilder sbLogMsg = new StringBuilder(sLogMsg); if (dbRec.getType().equals(Pwdtypes.S_CREDS_TYPE) && (dbRec.getCredId() > 0)) { dbRec.setClientId(iClientId); dbRec.setCredId(iCredId); dbRec.setChallenge(jtxtChlng.getText().toString()); dbRec.setResponse(l_crypto.encrypt(jtxtRsp.getText().toString())); dbRec.setTrack(jcbTrack.getSelectedItem().toString()); /** Check for changes and insert log if necessary */ if (!sChallenge.equals(jtxtChlng.getText())) { sbLogMsg.append("Application [" + jtxtApp.getText() + "], Challenge modified, old [" + sChallenge + "], new [" + jtxtChlng.getText() + "]"); } if (!sResponse.equals(jtxtRsp.getText())) { if (sbLogMsg.toString().length() > 0) { sbLogMsg.append(","); } else { sbLogMsg.append("Application [" + jtxtApp.getText() + "],"); } sbLogMsg.append("Response modified, old [" + sResponse + "]"); } if (sbLogMsg.toString().length() > 0) { dbRecLog.setType(Pwdtypes.S_LOG_TYPE); dbRecLog.setLog(sbLogMsg.toString()); dbRecLog.setModifyDate(sCurDate); if (l_sqliteops.insertRecord(dbRecLog) < 0) { JOptionPane.showMessageDialog(null, "Insert log record failed [" + dbRecLog.getResult() + "]"); } } if (!jcbTrack.getSelectedItem().toString().equals("0")) { iDaysToAdd = Integer.parseInt(jcbTrack.getSelectedItem().toString()); calNow.add(Calendar.DATE, iDaysToAdd); sValue = sdf1.format(calNow.getTime()); System.out.println("DEBUG->Date (sValue) [" + sValue + "]"); dbRec.setModifyDate(sValue); } /// Update the record if (l_sqliteops.updateRecord(dbRec) < 0) { JOptionPane.showMessageDialog(null, "Update record failed [" + dbRec.getResult() + "]"); } else { int iRow = jtabCreds.getSelectedRow(); jtabCreds.setValueAt(jtxtChlng.getText().toString(), iRow, 1); jtabCreds.setValueAt(l_crypto.encrypt(jtxtRsp.getText().toString()), iRow, 2); jtabCreds.setValueAt(jcbTrack.getSelectedItem().toString(), iRow, 3); jtabCreds.setValueAt(sValue, iRow, 4); jtabCreds.setValueAt(sValue, iRow, 4); clearCredsFields(); enableCredsButtons(); } } } }); /// Button - Delete button for credentials btnCredDelete = new JButton("Delete"); btnCredDelete.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { dbRec.setType(Pwdtypes.S_CREDS_TYPE); dbRec.setCredId(iCredId); dbRec.setChallenge(jtxtChlng.getText().toString()); dbRec.setResponse(jtxtRsp.getText().toString()); if (l_sqliteops.deleteRecord(dbRec) < 0) { JOptionPane.showMessageDialog(null, "Delete credential record failed [" + dbRec.getResult() + "]"); } else { DefaultTableModel jtabModel = (DefaultTableModel) jtabCreds.getModel(); jtabModel.removeRow(jtabCreds.getSelectedRow()); clearCredsFields(); enableCredsButtons(); } } }); /// Button - Clear button for credentials btnCredClear = new JButton("Clear"); btnCredClear.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { clearCredsFields(); enableCredsButtons(); } }); /// End section for credentials challenges/responses - text fields and buttons JScrollPane scrollPane_1 = new JScrollPane(); scrollPane_1.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS); btnShowAssoc = new JButton("Display Associated Challenges/Responses in new window"); /// Display the challenges/responses associated to the application in a popup window. /// This is to make it easier to view when all of the values are needed btnShowAssoc.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { String sTitle = "Credentials for: " + jtxtApp.getText(); String sDisplay = ""; sDisplay += "\n"; DefaultTableModel jTmpModel = (DefaultTableModel) jtabCreds.getModel(); for (int i = 0; i < jTmpModel.getRowCount(); i++) { sDisplay += "Q. " + jTmpModel.getValueAt(i, 1).toString() + " A. " + l_crypto.decrypt(jTmpModel.getValueAt(i, 2).toString()) + "\n"; } JOptionPane.showMessageDialog(null, sDisplay, sTitle, JOptionPane.INFORMATION_MESSAGE); } }); JLabel lblTrackUpdates = new JLabel("Exp Days"); /// Values for expiration days are hardcoded, may want to move to a table for metadata jcbTrack.addItem("0"); jcbTrack.addItem("30"); jcbTrack.addItem("45"); jcbTrack.addItem("60"); jcbTrack.addItem("90"); jcbTrack.addItem("180"); jcbTrack.addItem("365"); jcbTrack.setSelectedItem("0"); btnEdit = new JButton("Edit"); btnEdit.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { jtxtChlng.setEnabled(true); jtxtRsp.setEnabled(true); jcbTrack.setEnabled(true); btnCredReplace.setEnabled(true); btnCredAdd.setEnabled(true); } }); btnEdit.setEnabled(false); GroupLayout gl_contentPane = new GroupLayout(contentPane); gl_contentPane.setHorizontalGroup(gl_contentPane.createParallelGroup(Alignment.LEADING) .addGroup(gl_contentPane.createSequentialGroup().addGroup(gl_contentPane .createParallelGroup(Alignment.LEADING) .addGroup(gl_contentPane.createSequentialGroup().addGap(207) .addComponent(lblThePasswordSaver)) .addGroup(gl_contentPane.createSequentialGroup().addGap(23).addGroup(gl_contentPane .createParallelGroup(Alignment.LEADING) .addGroup(gl_contentPane.createSequentialGroup().addComponent(btnAdd) .addPreferredGap(ComponentPlacement.RELATED).addComponent(btnReplace) .addPreferredGap(ComponentPlacement.RELATED).addComponent(btnDelete) .addPreferredGap(ComponentPlacement.RELATED).addComponent(btnSearch) .addPreferredGap(ComponentPlacement.RELATED).addComponent(btnClear)) .addGroup(gl_contentPane.createSequentialGroup().addGroup(gl_contentPane .createParallelGroup(Alignment.LEADING) .addGroup(gl_contentPane.createSequentialGroup() .addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING) .addComponent(lblUrlapplication) .addComponent(lblDescription)) .addPreferredGap(ComponentPlacement.RELATED) .addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING) .addComponent(jtxtApp, GroupLayout.PREFERRED_SIZE, 154, GroupLayout.PREFERRED_SIZE) .addComponent(jtxtDesc, GroupLayout.PREFERRED_SIZE, 260, GroupLayout.PREFERRED_SIZE))) .addComponent(scrollPane, GroupLayout.PREFERRED_SIZE, 355, GroupLayout.PREFERRED_SIZE)) .addPreferredGap(ComponentPlacement.RELATED, 18, Short.MAX_VALUE) .addGroup(gl_contentPane.createParallelGroup(Alignment.TRAILING) .addComponent(btnShowAssoc) .addGroup(gl_contentPane.createSequentialGroup() .addGroup(gl_contentPane .createParallelGroup(Alignment.TRAILING) .addComponent(lblResponse) .addComponent(lblChallenge)) .addGap(18) .addGroup(gl_contentPane .createParallelGroup(Alignment.LEADING) .addGroup(gl_contentPane.createSequentialGroup() .addComponent(jtxtRsp, 272, 272, 272) .addGap(26).addComponent(lblTrackUpdates) .addPreferredGap( ComponentPlacement.UNRELATED) .addComponent(jcbTrack, GroupLayout.PREFERRED_SIZE, 55, GroupLayout.PREFERRED_SIZE)) .addComponent(jtxtChlng, GroupLayout.PREFERRED_SIZE, 440, GroupLayout.PREFERRED_SIZE))) .addGroup(gl_contentPane .createParallelGroup(Alignment.LEADING, false) .addGroup(gl_contentPane.createSequentialGroup() .addComponent(btnCredAdd, GroupLayout.PREFERRED_SIZE, 78, GroupLayout.PREFERRED_SIZE) .addPreferredGap(ComponentPlacement.RELATED) .addComponent(btnCredReplace) .addPreferredGap(ComponentPlacement.RELATED) .addComponent(btnCredDelete, GroupLayout.PREFERRED_SIZE, 75, GroupLayout.PREFERRED_SIZE) .addPreferredGap(ComponentPlacement.UNRELATED) .addComponent(btnCredClear) .addPreferredGap(ComponentPlacement.RELATED, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(btnEdit)) .addComponent(scrollPane_1, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)))))) .addGroup(gl_contentPane.createSequentialGroup().addGap(36).addComponent(chkDelAssoc))) .addContainerGap(57, Short.MAX_VALUE))); gl_contentPane.setVerticalGroup(gl_contentPane.createParallelGroup(Alignment.LEADING) .addGroup(gl_contentPane.createSequentialGroup().addContainerGap().addComponent(lblThePasswordSaver) .addGap(45) .addGroup(gl_contentPane.createParallelGroup(Alignment.TRAILING) .addGroup(gl_contentPane.createSequentialGroup().addGroup(gl_contentPane .createParallelGroup(Alignment.BASELINE).addComponent(lblUrlapplication) .addComponent(jtxtApp, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) .addComponent(lblChallenge)).addPreferredGap(ComponentPlacement.UNRELATED) .addGroup(gl_contentPane.createParallelGroup(Alignment.BASELINE) .addComponent(lblDescription) .addComponent(jtxtDesc, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) .addComponent(lblResponse))) .addGroup(gl_contentPane.createSequentialGroup() .addComponent(jtxtChlng, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) .addPreferredGap(ComponentPlacement.UNRELATED) .addGroup(gl_contentPane.createParallelGroup(Alignment.BASELINE) .addComponent(jtxtRsp, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) .addComponent(lblTrackUpdates) .addComponent(jcbTrack, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)))) .addGap(18) .addGroup(gl_contentPane.createParallelGroup(Alignment.BASELINE).addComponent(btnAdd) .addComponent(btnReplace).addComponent(btnDelete).addComponent(btnSearch) .addComponent(btnClear).addComponent(btnCredAdd).addComponent(btnCredReplace) .addComponent(btnCredDelete).addComponent(btnCredClear).addComponent(btnEdit)) .addPreferredGap(ComponentPlacement.UNRELATED) .addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING) .addGroup(gl_contentPane.createParallelGroup(Alignment.BASELINE) .addComponent(scrollPane, GroupLayout.PREFERRED_SIZE, 208, GroupLayout.PREFERRED_SIZE) .addComponent(scrollPane_1, GroupLayout.PREFERRED_SIZE, 109, GroupLayout.PREFERRED_SIZE)) .addGroup(gl_contentPane.createSequentialGroup().addGap(120) .addComponent(btnShowAssoc))) .addGap(18).addComponent(chkDelAssoc).addContainerGap(170, Short.MAX_VALUE))); /// JTable - Credentials table setup/definition - BEGIN jtabCreds = new JTable(); jtabCreds.setModel(new DefaultTableModel(new Object[][] {}, new String[] { "ID", "Challenge", "Response", "Exp Days", "Expiration Date" }) { Class[] columnTypes = new Class[] { Integer.class, String.class, String.class, String.class, String.class }; public Class getColumnClass(int columnIndex) { return columnTypes[columnIndex]; } }); jtabCreds.setBorder(new MatteBorder(1, 1, 1, 1, (Color) new Color(0, 0, 0))); scrollPane_1.setViewportView(jtabCreds); /// JTable - Credentials table setup/definition - END jtabApps = new JTable(); scrollPane.setViewportView(jtabApps); jtabApps.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); jtabApps.setBorder(new MatteBorder(1, 1, 1, 1, (Color) new Color(0, 0, 0))); jtabApps.setModel( new DefaultTableModel(new Object[][] {}, new String[] { "ID", "URL/Application", "Description" }) { Class[] columnTypes = new Class[] { Integer.class, String.class, String.class }; public Class getColumnClass(int columnIndex) { return columnTypes[columnIndex]; } @Override public boolean isCellEditable(int row, int column) { //all cells false return false; } }); jtabApps.getColumnModel().getColumn(1).setMinWidth(55); jtabApps.getColumnModel().getColumn(2).setMinWidth(55); contentPane.setLayout(gl_contentPane); contentPane.setFocusTraversalPolicy(new FocusTraversalOnArray(new Component[] { jtxtChlng, lblThePasswordSaver, jtxtApp, jtxtDesc, btnAdd, btnReplace, btnDelete, btnSearch, btnClear, jtxtRsp, btnCredAdd, btnCredReplace, btnCredDelete, btnCredClear, scrollPane, jtabApps, lblUrlapplication, lblDescription, chkDelAssoc, lblChallenge, lblResponse, scrollPane_1, jtabCreds })); setFocusTraversalPolicy(new FocusTraversalOnArray( new Component[] { menuBar, jtxtApp, jtxtDesc, btnAdd, btnReplace, btnDelete, btnSearch, btnClear, jtxtChlng, jtxtRsp, btnCredAdd, btnCredReplace, btnCredDelete, btnCredClear, contentPane, mnFile, mntmExit, lblThePasswordSaver, scrollPane, jtabApps, lblUrlapplication, lblDescription, chkDelAssoc, lblChallenge, lblResponse, scrollPane_1, jtabCreds })); /// Initial data load dbRec = new DbRecord(); dbRec.setType(Pwdtypes.S_CLIENT_TYPE); dbRec.setClientName(""); dbRec.setClientDesc(""); loadTable(dbRec); disableCredsButtons(); ListSelectionModel rowSM = jtabApps.getSelectionModel(); //Listener for client row change; rowSM.addListSelectionListener(new ListSelectionListener() { /// Fill the form values when a row is selected in the JTable @Override public void valueChanged(ListSelectionEvent e) { ListSelectionModel lsmData = (ListSelectionModel) e.getSource(); if (!lsmData.isSelectionEmpty()) { int iRow = lsmData.getMinSelectionIndex(); iClientId = Integer.parseInt(jtabApps.getValueAt(iRow, 0).toString()); jtxtApp.setText(jtabApps.getValueAt(iRow, 1).toString()); jtxtDesc.setText(jtabApps.getValueAt(iRow, 2).toString()); dbRec.setType(Pwdtypes.S_CREDS_TYPE); dbRec.setClientId(iClientId); loadTable(dbRec); enableButtons(); clearCredsFields(); enableCredsButtons(); } } }); ListSelectionModel rowCred = jtabCreds.getSelectionModel(); //Listener for credential row change; rowCred.addListSelectionListener(new ListSelectionListener() { /// Fill the form values when a row is selected in the JTable @Override public void valueChanged(ListSelectionEvent e) { ListSelectionModel lsmData = (ListSelectionModel) e.getSource(); if (!lsmData.isSelectionEmpty()) { int iRow = lsmData.getMinSelectionIndex(); iCredId = Integer.parseInt(jtabCreds.getValueAt(iRow, 0).toString()); jtxtChlng.setText(jtabCreds.getValueAt(iRow, 1).toString()); jtxtRsp.setText(l_crypto.decrypt(jtabCreds.getValueAt(iRow, 2).toString())); jcbTrack.setSelectedItem(jtabCreds.getValueAt(iRow, 3).toString()); if (null == jtabCreds.getValueAt(iRow, 4)) { sDateModified = ""; } else { sDateModified = jtabCreds.getValueAt(iRow, 4).toString(); } sChallenge = jtxtChlng.getText(); sResponse = jtxtRsp.getText(); dbRec.setType(Pwdtypes.S_CREDS_TYPE); dbRec.setCredId(iClientId); jtxtChlng.setEnabled(false); jtxtRsp.setEnabled(false); jcbTrack.setEnabled(false); btnEdit.setEnabled(true); btnCredDelete.setEnabled(true); btnCredClear.setEnabled(true); } } }); }