List of usage examples for javax.swing.event ListSelectionListener ListSelectionListener
ListSelectionListener
From source file:org.signserver.admin.gui.AddWorkerDialog.java
/** Creates new form AddWorkerDialog */ public AddWorkerDialog(java.awt.Frame parent, boolean modal) { super(parent, modal); initComponents();//from www.j a v a 2 s .c o m stage = Stage.INITIAL_CONFIG; mode = Mode.LOAD_FROM_FILE; loadFromFileRadioButton.setSelected(true); updateControls(); // initially set the Next button to be greyed-out, so that it can be // enabled based on the state nextApplyButton.setEnabled(false); invalidWorkerIdStatusLabel.setVisible(false); propertiesTable.setDefaultRenderer(String.class, new DefaultTableCellRenderer() { @Override public Component getTableCellRendererComponent(JTable table, Object value, boolean selected, boolean focused, int row, int column) { setEnabled(table == null || table.isEnabled()); super.getTableCellRendererComponent(table, value, selected, focused, row, column); return this; } }); propertiesTable.getSelectionModel().addListSelectionListener(new ListSelectionListener() { @Override public void valueChanged(final ListSelectionEvent e) { if (!e.getValueIsAdjusting()) { final boolean enable = propertiesTable.getSelectedRowCount() == 1; editPropertyButton.setEnabled(enable); removePropertyButton.setEnabled(enable); } } }); // add a document listner to update the UI when the content of the ID // combobox changes final JTextComponent component = (JTextComponent) workerIdComboBox.getEditor().getEditorComponent(); component.getDocument().addDocumentListener(new DocumentListener() { @Override public void insertUpdate(DocumentEvent ev) { updateControls(); } @Override public void removeUpdate(DocumentEvent ev) { updateControls(); } @Override public void changedUpdate(DocumentEvent ev) { updateControls(); } }); // add a document listner to update the UI on updates of the configuration text configurationTextArea.getDocument().addDocumentListener(new DocumentListener() { @Override public void insertUpdate(DocumentEvent ev) { configurationEdited = true; updateControls(); } @Override public void removeUpdate(DocumentEvent ev) { configurationEdited = true; updateControls(); } @Override public void changedUpdate(DocumentEvent ev) { configurationEdited = true; updateControls(); } }); }
From source file:org.signserver.admin.gui.MainView.java
public MainView(SingleFrameApplication app) { super(app);// w ww. ja v a2s .c om initComponents(); final int rowHeights = new JComboBox/*<String>*/().getPreferredSize().height; // workaround a bug in the NetBeans form editor where the download // archive entries button sometimes looses its default disabled state downloadArchiveEntriesButton.setEnabled(false); statusSummaryTextPane.setContentType("text/html"); auditlogConditionsModel.addCondition(AuditlogColumn.EVENTTYPE, RelationalOperator.NEQ, "ACCESS_CONTROL"); auditLogTable.setModel(auditlogModel); archiveTable.setModel(archiveModel); conditionsTable.setModel(auditlogConditionsModel); conditionsTable.getSelectionModel().addListSelectionListener(new ListSelectionListener() { @Override public void valueChanged(ListSelectionEvent e) { if (!e.getValueIsAdjusting()) { jButtonAuditConditionRemove.setEnabled(conditionsTable.getSelectedRowCount() > 0); } } }); jTabbedPane1.setSelectedComponent(mainPanel); archiveConditionsTable.setModel(archiveConditionsModel); archiveConditionsTable.getSelectionModel().addListSelectionListener(new ListSelectionListener() { @Override public void valueChanged(ListSelectionEvent e) { if (!e.getValueIsAdjusting()) { jButtonArchiveConditionRemove.setEnabled(archiveConditionsTable.getSelectedRowCount() > 0); } } }); tokenEntriesTable.setModel(tokenEntriesModel); tokenEntriesTable.getSelectionModel().addListSelectionListener(new ListSelectionListener() { @Override public void valueChanged(final ListSelectionEvent e) { if (!e.getValueIsAdjusting()) { final boolean exactlyOneSelected = tokenEntriesTable.getSelectedRowCount() == 1; final boolean anySelected = tokenEntriesTable.getSelectedRowCount() > 0; tokenEntriesTestButton.setEnabled(exactlyOneSelected); tokenEntriesGenerateCSRButton.setEnabled(anySelected); tokenEntriesImportButton.setEnabled(anySelected); tokenEntriesRemoveButton.setEnabled(exactlyOneSelected); tokenEntriesDetailsButton.setEnabled(exactlyOneSelected); } } }); final String action = "DetailsOnEnter"; KeyStroke enter = KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0); tokenEntriesTable.getInputMap(JTable.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).put(enter, action); tokenEntriesTable.getActionMap().put(action, new AbstractAction() { @Override public void actionPerformed(ActionEvent e) { if (tokenEntriesTable.getSelectedRows().length > 0) { tokenEntriesDetailsButton.doClick(); } } }); workersList.setCellRenderer(new MyListCellRenderer()); workersList.getSelectionModel().addListSelectionListener(new ListSelectionListener() { @Override public void valueChanged(final ListSelectionEvent evt) { if (!evt.getValueIsAdjusting()) { selectedWorkers = new ArrayList<Worker>(); for (Object o : workersList.getSelectedValues()) { if (o instanceof Worker) { selectedWorkers.add((Worker) o); } } workerComboBox.setModel(new MyComboBoxModel(selectedWorkers)); // removeKey should only be enabled iff one selected removeKeyMenu.setEnabled(selectedWorkers.size() == 1); if (selectedWorkers.size() > 0) { if (LOG.isDebugEnabled()) { LOG.debug("Previously selected: " + selectedWorkerBeforeRefresh); } int comboBoxSelection = 0; // Try to set the previously selected if (selectedWorkerBeforeRefresh != null) { comboBoxSelection = selectedWorkers.indexOf(selectedWorkerBeforeRefresh); if (comboBoxSelection == -1) { comboBoxSelection = 0; } } workerComboBox.setSelectedIndex(comboBoxSelection); } else { displayWorker(null); } } } }); workerComboBox.setRenderer(new SmallWorkerListCellRenderer()); workerComboBox.addActionListener(new ActionListener() { @Override public void actionPerformed(final ActionEvent e) { if (workerComboBox.getSelectedItem() instanceof Worker) { displayWorker((Worker) workerComboBox.getSelectedItem()); } } }); propertiesTable.getSelectionModel().addListSelectionListener(new ListSelectionListener() { @Override public void valueChanged(final ListSelectionEvent e) { if (!e.getValueIsAdjusting()) { final int row = propertiesTable.getSelectedRow(); final boolean enable; if (row == -1) { enable = false; } else { final Object o = propertiesTable.getValueAt(row, 1); enable = o instanceof X509Certificate || o instanceof Collection; // TODO: Too weak } statusPropertiesDetailsButton.setEnabled(enable); } } }); propertiesTable.setRowHeight(rowHeights); configurationTable.getSelectionModel().addListSelectionListener(new ListSelectionListener() { @Override public void valueChanged(final ListSelectionEvent e) { if (!e.getValueIsAdjusting()) { final boolean enable = configurationTable.getSelectedRowCount() == 1; editButton.setEnabled(enable); removeButton.setEnabled(enable); } } }); configurationTable.setRowHeight(rowHeights); authTable.getSelectionModel().addListSelectionListener(new ListSelectionListener() { @Override public void valueChanged(final ListSelectionEvent e) { if (!e.getValueIsAdjusting()) { final boolean enable = authTable.getSelectedRowCount() == 1; authEditButton.setEnabled(enable); authRemoveButton.setEnabled(enable); } } }); authTable.setRowHeight(rowHeights); archiveTable.getSelectionModel().addListSelectionListener(new ListSelectionListener() { @Override public void valueChanged(ListSelectionEvent e) { if (!e.getValueIsAdjusting()) { downloadArchiveEntriesButton .setEnabled(!fetchArchiveDataInProgress && archiveTable.getSelectedRowCount() > 0); } } }); archiveTable.setRowHeight(rowHeights); auditLogTable.setRowHeight(rowHeights); conditionsTable.setRowHeight(rowHeights); archiveConditionsTable.setRowHeight(rowHeights); tokenEntriesTable.setRowHeight(rowHeights); displayWorker(null); // status bar initialization - message timeout, idle icon and busy // animation, etc ResourceMap resourceMap = getResourceMap(); int messageTimeout = resourceMap.getInteger("StatusBar.messageTimeout"); messageTimer = new Timer(messageTimeout, new ActionListener() { @Override public void actionPerformed(ActionEvent e) { statusMessageLabel.setText(""); } }); messageTimer.setRepeats(false); int busyAnimationRate = resourceMap.getInteger("StatusBar.busyAnimationRate"); for (int i = 0; i < busyIcons.length; i++) { busyIcons[i] = resourceMap.getIcon("StatusBar.busyIcons[" + i + "]"); } busyIconTimer = new Timer(busyAnimationRate, new ActionListener() { @Override public void actionPerformed(ActionEvent e) { busyIconIndex = (busyIconIndex + 1) % busyIcons.length; statusAnimationLabel.setIcon(busyIcons[busyIconIndex]); } }); idleIcon = resourceMap.getIcon("StatusBar.idleIcon"); statusAnimationLabel.setIcon(idleIcon); progressBar.setVisible(false); // connecting action tasks to status bar via TaskMonitor TaskMonitor taskMonitor = new TaskMonitor(getApplication().getContext()); taskMonitor.addPropertyChangeListener(new PropertyChangeListener() { @Override public void propertyChange(PropertyChangeEvent evt) { String propertyName = evt.getPropertyName(); if ("started".equals(propertyName)) { if (!busyIconTimer.isRunning()) { statusAnimationLabel.setIcon(busyIcons[0]); busyIconIndex = 0; busyIconTimer.start(); } progressBar.setVisible(true); progressBar.setIndeterminate(true); } else if ("done".equals(propertyName)) { busyIconTimer.stop(); statusAnimationLabel.setIcon(idleIcon); progressBar.setVisible(false); progressBar.setValue(0); } else if ("message".equals(propertyName)) { String text = (String) evt.getNewValue(); statusMessageLabel.setText((text == null) ? "" : text); messageTimer.restart(); } else if ("progress".equals(propertyName)) { int value = (Integer) evt.getNewValue(); progressBar.setVisible(true); progressBar.setIndeterminate(false); progressBar.setValue(value); } } }); getContext().getTaskService().execute(refreshWorkers()); }
From source file:org.signserver.admin.gui.ViewCertificateFrame.java
public ViewCertificateFrame(final List<X509Certificate> certificates) { this.certificates = certificates; this.certificate = certificates.get(0); initComponents();// ww w . j ava 2s.c o m chainList.setModel(new AbstractListModel() { @Override public int getSize() { return certificates.size(); } @Override public Object getElementAt(int index) { return certificates.get(index); } }); chainList.setCellRenderer(new DefaultListCellRenderer() { @Override public Component getListCellRendererComponent(final JList list, Object value, final int index, final boolean isSelected, final boolean cellHasFocus) { if (value instanceof X509Certificate) { final X509Certificate cert = (X509Certificate) value; value = cert.getSubjectDN().getName(); } return super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus); } }); chainList.getSelectionModel().addListSelectionListener(new ListSelectionListener() { @Override public void valueChanged(final ListSelectionEvent evt) { if (!evt.getValueIsAdjusting()) { viewCertificate((X509Certificate) chainList.getSelectedValue()); } } }); fieldsList.setCellRenderer(new DefaultListCellRenderer() { @Override public Component getListCellRendererComponent(final JList list, Object value, final int index, final boolean isSelected, final boolean cellHasFocus) { if (value instanceof Field) { value = ((Field) value).getName(); } return super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus); } }); fieldsList.getSelectionModel().addListSelectionListener(new ListSelectionListener() { @Override public void valueChanged(final ListSelectionEvent evt) { if (!evt.getValueIsAdjusting()) { viewFieldValue((Field) fieldsList.getSelectedValue()); } } }); subjectTextArea.setText(certificate.getSubjectDN().getName()); issuerTextArea.setText(certificate.getIssuerDN().getName()); serialNumberField.setText(certificate.getSerialNumber().toString(16)); notBeforeLabel.setText(String.valueOf(certificate.getNotBefore())); notAfterLabel.setText(String.valueOf(certificate.getNotAfter())); String fingerprint = ""; try { fingerprint = calcFingerprint(certificate.getEncoded()); } catch (CertificateEncodingException ex) { LOG.error("Error calculating certificate fingerprint", ex); } fingerprintLabel.setText(fingerprint); usages = new ArrayList<String>(); boolean[] keyUsages = certificate.getKeyUsage(); if (keyUsages != null) { // digitalSignature (0), if (keyUsages[0]) { usages.add("digitalSignature"); } // nonRepudiation (1), if (keyUsages[1]) { usages.add("nonRepudiation"); } // keyEncipherment (2), if (keyUsages[2]) { usages.add("keyEncipherment"); } // dataEncipherment (3), if (keyUsages[3]) { usages.add("dataEncipherment"); } // keyAgreement (4), if (keyUsages[4]) { usages.add("keyAgreement"); } // keyCertSign (5), if (keyUsages[5]) { usages.add("keyCertSign"); } // cRLSign (6), if (keyUsages[6]) { usages.add("cRLSign"); } // encipherOnly (7), if (keyUsages[7]) { usages.add("encipherOnly"); } // decipherOnly if (keyUsages[8]) { usages.add("decipherOnly"); } } try { final List<String> eku = certificate.getExtendedKeyUsage(); if (eku != null) { usages.addAll(eku); } } catch (CertificateParsingException ex) { LOG.error("Error getting extended key usage", ex); } usagesList.setModel(new AbstractListModel() { @Override public int getSize() { return usages.size(); } @Override public Object getElementAt(int index) { return usages.get(index); } }); chainList.setSelectedIndex(0); }
From source file:org.simmi.GeneSetHead.java
License:asdf
public List getSelspecContigs(List<JComponent> complist, final Map<String, List<Sequence>> speccontigMap, final String... selspec) { List<Sequence> contigs = null; final List<String> specs = new ArrayList<String>(speccontigMap.keySet()); final JTable stable = new JTable(); stable.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); final TableModel stablemodel = new TableModel() { @Override// w w w.j a v a 2s . c om public int getRowCount() { return specs.size(); } @Override public int getColumnCount() { return 1; } @Override public String getColumnName(int columnIndex) { return "Species"; } @Override public Class<?> getColumnClass(int columnIndex) { return String.class; } @Override public boolean isCellEditable(int rowIndex, int columnIndex) { return false; } @Override public Object getValueAt(int rowIndex, int columnIndex) { if (rowIndex >= 0 && rowIndex < specs.size()) return specs.get(rowIndex); return null; } @Override public void setValueAt(Object aValue, int rowIndex, int columnIndex) { } @Override public void addTableModelListener(TableModelListener l) { } @Override public void removeTableModelListener(TableModelListener l) { } }; stable.setModel(stablemodel); final JTable ctable = new JTable(); ctable.setAutoCreateRowSorter(true); final TableModel ctablemodel = new TableModel() { @Override public int getRowCount() { int r = stable.getSelectedRow(); String spec = selspec.length > 0 ? selspec[0] : (String) stable.getValueAt(r, 0); if (spec != null) { List<Sequence> contigs = geneset.speccontigMap.get(spec); return contigs.size(); } return 0; } @Override public int getColumnCount() { return 1; } @Override public String getColumnName(int columnIndex) { return "Contigs"; } @Override public Class<?> getColumnClass(int columnIndex) { return Sequence.class; } @Override public boolean isCellEditable(int rowIndex, int columnIndex) { return false; } @Override public Object getValueAt(int rowIndex, int columnIndex) { int r = stable.getSelectedRow(); String spec = selspec.length > 0 ? selspec[0] : (String) stable.getValueAt(r, 0); List<Sequence> contigs = geneset.speccontigMap.get(spec); return contigs.get(rowIndex); } @Override public void setValueAt(Object aValue, int rowIndex, int columnIndex) { } @Override public void addTableModelListener(TableModelListener l) { } @Override public void removeTableModelListener(TableModelListener l) { } }; ctable.setModel(ctablemodel); JScrollPane sscrollpane = new JScrollPane(stable); JScrollPane cscrollpane = new JScrollPane(ctable); FlowLayout flowlayout = new FlowLayout(); JComponent c = new JComponent() { }; c.setLayout(flowlayout); if (selspec.length == 0) c.add(sscrollpane); c.add(cscrollpane); if (complist != null) { for (JComponent comp : complist) { c.add(comp); } } stable.getSelectionModel().addListSelectionListener(new ListSelectionListener() { @Override public void valueChanged(ListSelectionEvent e) { ctable.tableChanged(new TableModelEvent(ctablemodel)); } }); JOptionPane.showMessageDialog(this, c); int[] rr = stable.getSelectedRows(); if (rr.length > 1) { List slist = new ArrayList(); for (int r : rr) { int i = stable.convertRowIndexToModel(r); slist.add(specs.get(i)); } return slist; } else { int sr = stable.getSelectedRow(); String spec = selspec.length > 0 ? selspec[0] : (String) stable.getValueAt(sr, 0); if (spec != null) { List<Sequence> ctgs = geneset.speccontigMap.get(spec); rr = ctable.getSelectedRows(); contigs = new ArrayList<Sequence>(); for (int r : rr) { int i = ctable.convertRowIndexToModel(r); contigs.add(ctgs.get(i)); } } return contigs; } }
From source file:org.spottedplaid.ui.Mainframe.java
/** * Create the frame.// w w w. j a va 2 s . c o m * * @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); } } }); }
From source file:org.stanwood.nwn2.gui.MainWindow.java
private void createComponents(JPanel panel1) { BorderLayout layout = new BorderLayout(5, 5); panel1.setLayout(layout);/*from w ww . j a va 2s. c o m*/ JLabel lblList = new JLabel("Neverwinter Nights 2 GUI XML files:"); panel1.add(lblList, BorderLayout.NORTH); JPanel panel = new JPanel(); panel.setLayout(new BorderLayout(5, 5)); guiFileListModel = new DefaultListModel(); guiFileList = new JList(guiFileListModel); guiFileList.addListSelectionListener(new ListSelectionListener() { @Override public void valueChanged(ListSelectionEvent e) { updateEnabledState(); } }); JScrollPane pane = new JScrollPane(guiFileList); JPanel buttonPanel1 = new JPanel(); buttonPanel1.setLayout(new BorderLayout()); panel.add(buttonPanel1, BorderLayout.EAST); JPanel buttonPanel2 = new JPanel(); buttonPanel1.add(buttonPanel2, BorderLayout.NORTH); buttonPanel2.setLayout(new GridLayout(4, 1, 5, 5)); JButton cmdAdd = new JButton( IconManager.getInstance().getIcon(IconManager.SIZE_22, IconManager.ICON_LIST_ADD)); cmdAdd.setToolTipText("Add a XML GUI file to the list"); cmdAdd.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { addNewGUIFile(); } }); buttonPanel2.add(cmdAdd); cmdRemove = new JButton( IconManager.getInstance().getIcon(IconManager.SIZE_22, IconManager.ICON_LIST_REMOVE)); cmdRemove.setToolTipText("Remove the selected XML GUI file from the list"); cmdRemove.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { guiFileListModel.remove(guiFileList.getSelectedIndex()); updateEnabledState(); saveChanges(); } }); buttonPanel2.add(cmdRemove); cmdDisplay = new JButton( IconManager.getInstance().getIcon(IconManager.SIZE_22, IconManager.ICON_LIST_VIEW)); cmdDisplay.setToolTipText("Render the selected XML GUI file"); cmdDisplay.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { displayGUIFile(); } }); buttonPanel2.add(cmdDisplay); cmdEdit = new JButton( IconManager.getInstance().getIcon(IconManager.SIZE_22, IconManager.ICON_ACCESSORIES_TEXT_EDITOR)); cmdEdit.setToolTipText("Open the selected XML GUI file in a editor"); cmdEdit.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { File guiFile = getSelectedFile(); try { Desktop.getDesktop().edit(guiFile); } catch (IOException e1) { JOptionPane.showMessageDialog(MainWindow.this, e1.getMessage(), "NWN2GUI Error", JOptionPane.ERROR_MESSAGE); log.error(e1.getMessage(), e1); } catch (UnsupportedOperationException e1) { //TODO add support for other platforms JOptionPane.showMessageDialog(MainWindow.this, "Unable to find the systems default editor", "NWN2GUI Error", JOptionPane.ERROR_MESSAGE); } } }); buttonPanel2.add(cmdEdit); panel.add(pane, BorderLayout.CENTER); panel1.add(panel, BorderLayout.CENTER); }
From source file:org.tinymediamanager.ui.movies.settings.MovieImageSettingsPanel.java
/** * Instantiates a new movie image settings panel. *//*from ww w .j a v a 2 s. c om*/ public MovieImageSettingsPanel() { // data init List<String> enabledArtworkProviders = settings.getMovieArtworkScrapers(); int selectedIndex = -1; int counter = 0; for (MediaScraper scraper : MovieList.getInstance().getAvailableArtworkScrapers()) { ArtworkScraper artworkScraper = new ArtworkScraper(scraper); if (enabledArtworkProviders.contains(artworkScraper.getScraperId())) { artworkScraper.active = true; if (selectedIndex < 0) { selectedIndex = counter; } } scrapers.add(artworkScraper); counter++; } // init UI setLayout(new FormLayout( new ColumnSpec[] { FormSpecs.RELATED_GAP_COLSPEC, ColumnSpec.decode("default:grow"), FormSpecs.RELATED_GAP_COLSPEC, }, new RowSpec[] { FormSpecs.RELATED_GAP_ROWSPEC, FormSpecs.DEFAULT_ROWSPEC, FormSpecs.RELATED_GAP_ROWSPEC, FormSpecs.DEFAULT_ROWSPEC, FormSpecs.RELATED_GAP_ROWSPEC, })); JPanel panelMovieImages = new JPanel(); panelMovieImages.setBorder(new TitledBorder(null, BUNDLE.getString("Settings.poster"), TitledBorder.LEADING, //$NON-NLS-1$ TitledBorder.TOP, null, null)); add(panelMovieImages, "2, 2, default, fill"); panelMovieImages.setLayout(new FormLayout(new ColumnSpec[] { FormSpecs.RELATED_GAP_COLSPEC, FormSpecs.DEFAULT_COLSPEC, FormSpecs.RELATED_GAP_COLSPEC, ColumnSpec.decode("default:grow"), FormSpecs.RELATED_GAP_COLSPEC, ColumnSpec.decode("200dlu:grow"), FormSpecs.RELATED_GAP_COLSPEC, }, new RowSpec[] { FormSpecs.RELATED_GAP_ROWSPEC, RowSpec.decode("100dlu:grow"), FormSpecs.DEFAULT_ROWSPEC, FormSpecs.LABEL_COMPONENT_GAP_ROWSPEC, FormSpecs.DEFAULT_ROWSPEC, FormSpecs.LABEL_COMPONENT_GAP_ROWSPEC, FormSpecs.DEFAULT_ROWSPEC, FormSpecs.LABEL_COMPONENT_GAP_ROWSPEC, FormSpecs.DEFAULT_ROWSPEC, FormSpecs.LABEL_COMPONENT_GAP_ROWSPEC, FormSpecs.DEFAULT_ROWSPEC, })); scrollPaneScraperDetails = new JScrollPane(); scrollPaneScraperDetails.setBorder(null); scrollPaneScraperDetails.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER); panelMovieImages.add(scrollPaneScraperDetails, "6, 1, 1, 7, fill, fill"); panelScraperDetails = new ScrollablePanel(); scrollPaneScraperDetails.setViewportView(panelScraperDetails); panelScraperDetails .setLayout(new FormLayout(new ColumnSpec[] { ColumnSpec.decode("default:grow"), }, new RowSpec[] { FormSpecs.DEFAULT_ROWSPEC, FormSpecs.RELATED_GAP_ROWSPEC, FormSpecs.DEFAULT_ROWSPEC, })); { // add a CSS rule to force body tags to use the default label font // instead of the value in javax.swing.text.html.default.csss Font font = UIManager.getFont("Label.font"); String bodyRule = "body { font-family: " + font.getFamily() + "; " + "font-size: " + font.getSize() + "pt; }"; tpScraperDescription = new JTextPane(); tpScraperDescription.setOpaque(false); tpScraperDescription.setEditorKit(new HTMLEditorKit()); ((HTMLDocument) tpScraperDescription.getDocument()).getStyleSheet().addRule(bodyRule); panelScraperDetails.add(tpScraperDescription, "1, 1, fill, top"); } panelScraperOptions = new JPanel(); panelScraperOptions.setLayout(new FlowLayout(FlowLayout.LEFT)); panelScraperDetails.add(panelScraperOptions, "1, 3, fill, top"); scrollPaneScraper = new JScrollPane(); panelMovieImages.add(scrollPaneScraper, "2, 2, 3, 1, fill, fill"); tableScraper = new JTable(); tableScraper.setRowHeight(29); scrollPaneScraper.setViewportView(tableScraper); JSeparator separator = new JSeparator(); panelMovieImages.add(separator, "2, 3, 3, 1"); JLabel lblImageTmdbPosterSize = new JLabel(BUNDLE.getString("image.poster.size")); panelMovieImages.add(lblImageTmdbPosterSize, "2, 5"); cbImagePosterSize = new JComboBox(PosterSizes.values()); panelMovieImages.add(cbImagePosterSize, "4, 5"); JLabel lblImageTmdbFanartSize = new JLabel(BUNDLE.getString("image.fanart.size")); panelMovieImages.add(lblImageTmdbFanartSize, "2, 7"); cbImageFanartSize = new JComboBox(FanartSizes.values()); panelMovieImages.add(cbImageFanartSize, "4, 7"); separator = new JSeparator(); panelMovieImages.add(separator, "2, 9, 5, 1"); panelFileNaming = new JPanel(); panelMovieImages.add(panelFileNaming, "2, 11, 5, 1, fill, fill"); panelFileNaming.setLayout(new FormLayout( new ColumnSpec[] { FormSpecs.DEFAULT_COLSPEC, FormSpecs.RELATED_GAP_COLSPEC, FormSpecs.DEFAULT_COLSPEC, FormSpecs.RELATED_GAP_COLSPEC, FormSpecs.DEFAULT_COLSPEC, FormSpecs.RELATED_GAP_COLSPEC, FormSpecs.DEFAULT_COLSPEC, FormSpecs.RELATED_GAP_COLSPEC, FormSpecs.DEFAULT_COLSPEC, FormSpecs.RELATED_GAP_COLSPEC, ColumnSpec.decode("default:grow"), }, new RowSpec[] { FormSpecs.DEFAULT_ROWSPEC, FormSpecs.RELATED_GAP_ROWSPEC, FormSpecs.DEFAULT_ROWSPEC, FormSpecs.RELATED_GAP_ROWSPEC, FormSpecs.DEFAULT_ROWSPEC, })); JLabel lblPosterFilename = new JLabel(BUNDLE.getString("image.poster.naming")); panelFileNaming.add(lblPosterFilename, "1, 1"); cbMoviePosterFilename7 = new JCheckBox("<dynamic>.ext"); panelFileNaming.add(cbMoviePosterFilename7, "3, 1"); cbMoviePosterFilename4 = new JCheckBox("poster.ext"); panelFileNaming.add(cbMoviePosterFilename4, "5, 1"); cbMoviePosterFilename2 = new JCheckBox("movie.ext"); panelFileNaming.add(cbMoviePosterFilename2, "7, 1"); cbMoviePosterFilename8 = new JCheckBox("<dynamic>-poster.ext"); panelFileNaming.add(cbMoviePosterFilename8, "9, 1"); cbMoviePosterFilename6 = new JCheckBox("folder.ext"); panelFileNaming.add(cbMoviePosterFilename6, "11, 1"); JLabel lblFanartFileNaming = new JLabel(BUNDLE.getString("image.fanart.naming")); panelFileNaming.add(lblFanartFileNaming, "1, 3"); cbMovieFanartFilename1 = new JCheckBox("<dynamic>-fanart.ext"); panelFileNaming.add(cbMovieFanartFilename1, "3, 3"); cbMovieFanartFilename3 = new JCheckBox("<dynamic>.fanart.ext"); panelFileNaming.add(cbMovieFanartFilename3, "5, 3"); cbMovieFanartFilename2 = new JCheckBox("fanart.ext"); panelFileNaming.add(cbMovieFanartFilename2, "7, 3"); tpFileNamingHint = new JTextPane(); panelFileNaming.add(tpFileNamingHint, "1, 5, 11, 1, fill, fill"); tpFileNamingHint.setText(BUNDLE.getString("Settings.naming.info")); //$NON-NLS-1$ tpFileNamingHint.setBackground(UIManager.getColor("Panel.background")); TmmFontHelper.changeFont(tpFileNamingHint, 0.833); panelExtraArtwork = new JPanel(); panelExtraArtwork.setBorder(new TitledBorder(null, BUNDLE.getString("Settings.extraartwork"), TitledBorder.LEADING, TitledBorder.TOP, null, null)); add(panelExtraArtwork, "2, 4, default, fill"); panelExtraArtwork.setLayout(new FormLayout(new ColumnSpec[] { FormSpecs.RELATED_GAP_COLSPEC, ColumnSpec.decode("default:grow"), FormSpecs.RELATED_GAP_COLSPEC, ColumnSpec.decode("default:grow"), FormSpecs.RELATED_GAP_COLSPEC, ColumnSpec.decode("default:grow"), FormSpecs.RELATED_GAP_COLSPEC, ColumnSpec.decode("default:grow"), FormSpecs.RELATED_GAP_COLSPEC, ColumnSpec.decode("default:grow"), FormSpecs.RELATED_GAP_COLSPEC, }, new RowSpec[] { FormSpecs.RELATED_GAP_ROWSPEC, FormSpecs.DEFAULT_ROWSPEC, FormSpecs.RELATED_GAP_ROWSPEC, FormSpecs.DEFAULT_ROWSPEC, FormSpecs.RELATED_GAP_ROWSPEC, FormSpecs.DEFAULT_ROWSPEC, FormSpecs.RELATED_GAP_ROWSPEC, FormSpecs.DEFAULT_ROWSPEC, FormSpecs.RELATED_GAP_ROWSPEC, FormSpecs.DEFAULT_ROWSPEC, FormSpecs.RELATED_GAP_ROWSPEC, FormSpecs.DEFAULT_ROWSPEC, FormSpecs.RELATED_GAP_ROWSPEC, FormSpecs.DEFAULT_ROWSPEC, FormSpecs.RELATED_GAP_ROWSPEC, FormSpecs.DEFAULT_ROWSPEC, FormSpecs.RELATED_GAP_ROWSPEC, FormSpecs.DEFAULT_ROWSPEC, FormSpecs.RELATED_GAP_ROWSPEC, FormSpecs.DEFAULT_ROWSPEC, FormSpecs.RELATED_GAP_ROWSPEC, FormSpecs.DEFAULT_ROWSPEC, FormSpecs.RELATED_GAP_ROWSPEC, FormSpecs.DEFAULT_ROWSPEC, FormSpecs.RELATED_GAP_ROWSPEC, })); chckbxBanner = new JCheckBox(BUNDLE.getString("mediafiletype.banner")); panelExtraArtwork.add(chckbxBanner, "2, 2"); chckbxClearArt = new JCheckBox(BUNDLE.getString("mediafiletype.clearart")); panelExtraArtwork.add(chckbxClearArt, "4, 2"); chckbxThumb = new JCheckBox(BUNDLE.getString("mediafiletype.thumb")); panelExtraArtwork.add(chckbxThumb, "6, 2"); chckbxLogo = new JCheckBox(BUNDLE.getString("mediafiletype.logo")); panelExtraArtwork.add(chckbxLogo, "8, 2"); chckbxDiscArt = new JCheckBox(BUNDLE.getString("mediafiletype.discart")); panelExtraArtwork.add(chckbxDiscArt, "10, 2"); separator = new JSeparator(); panelExtraArtwork.add(separator, "2, 4, 9, 1"); chckbxEnableExtrathumbs = new JCheckBox(BUNDLE.getString("Settings.enable.extrathumbs")); panelExtraArtwork.add(chckbxEnableExtrathumbs, "2, 6, 3, 1"); chckbxResizeExtrathumbsTo = new JCheckBox(BUNDLE.getString("Settings.resize.extrathumbs")); panelExtraArtwork.add(chckbxResizeExtrathumbsTo, "6, 6, 3, 1"); spExtrathumbWidth = new JSpinner(); panelExtraArtwork.add(spExtrathumbWidth, "10, 6"); spExtrathumbWidth.setPreferredSize(new Dimension(49, 20)); lblDownload = new JLabel(BUNDLE.getString("Settings.amount.autodownload")); panelExtraArtwork.add(lblDownload, "2, 8, 7, 1, right, default"); spDownloadCountExtrathumbs = new JSpinner(); panelExtraArtwork.add(spDownloadCountExtrathumbs, "10, 8"); spDownloadCountExtrathumbs.setPreferredSize(new Dimension(49, 20)); chckbxEnableExtrafanart = new JCheckBox(BUNDLE.getString("Settings.enable.extrafanart")); panelExtraArtwork.add(chckbxEnableExtrafanart, "2, 10, 9, 1"); lblDownloadCount = new JLabel(BUNDLE.getString("Settings.amount.autodownload")); panelExtraArtwork.add(lblDownloadCount, "2, 12, 7, 1, right, default"); spDownloadCountExtrafanart = new JSpinner(); panelExtraArtwork.add(spDownloadCountExtrafanart, "10, 12"); spDownloadCountExtrafanart.setPreferredSize(new Dimension(49, 20)); separator = new JSeparator(); panelExtraArtwork.add(separator, "2, 14, 9, 1"); cbActorImages = new JCheckBox(BUNDLE.getString("Settings.actor.download")); panelExtraArtwork.add(cbActorImages, "2, 16, 9, 1"); separator = new JSeparator(); panelExtraArtwork.add(separator, "2, 18, 9, 1"); chckbxMovieSetArtwork = new JCheckBox(BUNDLE.getString("Settings.movieset.store.movie")); //$NON-NLS-1$ panelExtraArtwork.add(chckbxMovieSetArtwork, "2, 20, 9, 1"); chckbxStoreMoviesetArtwork = new JCheckBox(BUNDLE.getString("Settings.movieset.store")); //$NON-NLS-1$ panelExtraArtwork.add(chckbxStoreMoviesetArtwork, "2, 22, 9, 1"); lblFoldername = new JLabel(BUNDLE.getString("Settings.movieset.foldername")); //$NON-NLS-1$ panelExtraArtwork.add(lblFoldername, "2, 24, 3, 1, right, default"); tfMovieSetArtworkFolder = new JTextField(); panelExtraArtwork.add(tfMovieSetArtworkFolder, "6, 24, 3, 1"); tfMovieSetArtworkFolder.setColumns(10); btnSelectFolder = new JButton(BUNDLE.getString("Settings.movieset.buttonselect")); //$NON-NLS-1$ panelExtraArtwork.add(btnSelectFolder, "10, 24"); btnSelectFolder.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { Path file = TmmUIHelper.selectDirectory(BUNDLE.getString("Settings.movieset.folderchooser")); //$NON-NLS-1$ if (file != null && Files.isDirectory(file)) { tfMovieSetArtworkFolder.setText(file.toAbsolutePath().toString()); } } }); initDataBindings(); // poster filenames List<MoviePosterNaming> moviePosterFilenames = settings.getMoviePosterFilenames(); if (moviePosterFilenames.contains(MoviePosterNaming.MOVIE_JPG)) { cbMoviePosterFilename2.setSelected(true); } if (moviePosterFilenames.contains(MoviePosterNaming.POSTER_JPG)) { cbMoviePosterFilename4.setSelected(true); } if (moviePosterFilenames.contains(MoviePosterNaming.FOLDER_JPG)) { cbMoviePosterFilename6.setSelected(true); } if (moviePosterFilenames.contains(MoviePosterNaming.FILENAME_JPG)) { cbMoviePosterFilename7.setSelected(true); } if (moviePosterFilenames.contains(MoviePosterNaming.FILENAME_POSTER_JPG)) { cbMoviePosterFilename8.setSelected(true); } // fanart filenames List<MovieFanartNaming> movieFanartFilenames = settings.getMovieFanartFilenames(); if (movieFanartFilenames.contains(MovieFanartNaming.FILENAME_FANART_JPG)) { cbMovieFanartFilename1.setSelected(true); } if (movieFanartFilenames.contains(MovieFanartNaming.FANART_JPG)) { cbMovieFanartFilename2.setSelected(true); } if (movieFanartFilenames.contains(MovieFanartNaming.FILENAME_FANART2_JPG)) { cbMovieFanartFilename3.setSelected(true); } // listen to changes of the checkboxes ItemListener listener = new ItemListener() { public void itemStateChanged(ItemEvent e) { checkChanges(); } }; cbMovieFanartFilename2.addItemListener(listener); cbMovieFanartFilename3.addItemListener(listener); cbMovieFanartFilename1.addItemListener(listener); cbMoviePosterFilename2.addItemListener(listener); cbMoviePosterFilename4.addItemListener(listener); cbMoviePosterFilename7.addItemListener(listener); cbMoviePosterFilename8.addItemListener(listener); cbMoviePosterFilename6.addItemListener(listener); // adjust table columns // Checkbox and Logo shall have minimal width TableColumnResizer.setMaxWidthForColumn(tableScraper, 0, 2); TableColumnResizer.setMaxWidthForColumn(tableScraper, 1, 2); TableColumnResizer.adjustColumnPreferredWidths(tableScraper, 5); tableScraper.getModel().addTableModelListener(new TableModelListener() { @Override public void tableChanged(TableModelEvent arg0) { // click on the checkbox if (arg0.getColumn() == 0) { int row = arg0.getFirstRow(); ArtworkScraper changedScraper = scrapers.get(row); if (changedScraper.active) { settings.addMovieArtworkScraper(changedScraper.getScraperId()); } else { settings.removeMovieArtworkScraper(changedScraper.getScraperId()); } } } }); // implement selection listener to load settings tableScraper.getSelectionModel().addListSelectionListener(new ListSelectionListener() { @Override public void valueChanged(ListSelectionEvent e) { int index = tableScraper.convertRowIndexToModel(tableScraper.getSelectedRow()); if (index > -1) { panelScraperOptions.removeAll(); if (scrapers.get(index).getMediaProvider().getProviderInfo().getConfig().hasConfig()) { panelScraperOptions .add(new MediaScraperConfigurationPanel(scrapers.get(index).getMediaProvider())); } panelScraperOptions.revalidate(); } } }); // select default artwork scraper if (selectedIndex < 0) { selectedIndex = 0; } if (counter > 0) { tableScraper.getSelectionModel().setSelectionInterval(selectedIndex, selectedIndex); } }
From source file:org.tinymediamanager.ui.movies.settings.MovieScraperSettingsPanel.java
/** * Instantiates a new movie scraper settings panel. *///w ww . j a va2 s . c om public MovieScraperSettingsPanel() { // data init MediaScraper defaultMediaScraper = MovieList.getInstance().getDefaultMediaScraper(); int selectedIndex = 0; int counter = 0; for (MediaScraper scraper : MovieList.getInstance().getAvailableMediaScrapers()) { MovieScraper movieScraper = new MovieScraper(scraper); if (scraper.equals(defaultMediaScraper)) { movieScraper.defaultScraper = true; selectedIndex = counter; } scrapers.add(movieScraper); counter++; } // UI init setLayout(new FormLayout(new ColumnSpec[] { FormSpecs.RELATED_GAP_COLSPEC, FormSpecs.DEFAULT_COLSPEC, FormSpecs.RELATED_GAP_COLSPEC, ColumnSpec.decode("default:grow"), FormSpecs.RELATED_GAP_COLSPEC, }, new RowSpec[] { FormSpecs.RELATED_GAP_ROWSPEC, FormSpecs.DEFAULT_ROWSPEC, FormSpecs.RELATED_GAP_ROWSPEC, FormSpecs.DEFAULT_ROWSPEC, FormSpecs.RELATED_GAP_ROWSPEC, RowSpec.decode("default:grow"), })); JPanel panelMovieScrapers = new JPanel(); panelMovieScrapers.setBorder(new TitledBorder(UIManager.getBorder("TitledBorder.border"), BUNDLE.getString("scraper.metadata"), TitledBorder.LEADING, TitledBorder.TOP, null, null)); // $NON-NLS-1$ add(panelMovieScrapers, "2, 2, 3, 1, fill, fill"); panelMovieScrapers.setLayout(new FormLayout(new ColumnSpec[] { FormSpecs.RELATED_GAP_COLSPEC, FormSpecs.DEFAULT_COLSPEC, FormSpecs.RELATED_GAP_COLSPEC, ColumnSpec.decode("50dlu:grow"), FormSpecs.RELATED_GAP_COLSPEC, ColumnSpec.decode("200dlu:grow"), FormSpecs.RELATED_GAP_COLSPEC, }, new RowSpec[] { FormSpecs.RELATED_GAP_ROWSPEC, RowSpec.decode("150dlu:grow"), FormSpecs.LABEL_COMPONENT_GAP_ROWSPEC, FormSpecs.DEFAULT_ROWSPEC, FormSpecs.DEFAULT_ROWSPEC, FormSpecs.LABEL_COMPONENT_GAP_ROWSPEC, FormSpecs.DEFAULT_ROWSPEC, FormSpecs.DEFAULT_ROWSPEC, FormSpecs.DEFAULT_ROWSPEC, })); scrollPaneScraper = new JScrollPane(); panelMovieScrapers.add(scrollPaneScraper, "2, 2, 3, 1, fill, fill"); tableScraper = new JTable() { private static final long serialVersionUID = -144223066269069772L; @Override public java.awt.Component prepareRenderer(TableCellRenderer renderer, int row, int col) { java.awt.Component comp = super.prepareRenderer(renderer, row, col); String value = getModel().getValueAt(row, 2).toString(); if (!Globals.isDonator() && value.startsWith("Kodi")) { // FIXME: use scraper.isEnabled() somehow? comp.setBackground(Color.lightGray); comp.setEnabled(false); } else { comp.setBackground(Color.white); comp.setEnabled(true); } return comp; } }; tableScraper.setRowHeight(29); scrollPaneScraper.setViewportView(tableScraper); scrollPane = new JScrollPane(); scrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER); scrollPane.setBorder(null); panelMovieScrapers.add(scrollPane, "6, 1, 1, 7, fill, fill"); panelScraperDetails = new ScrollablePanel(); scrollPane.setViewportView(panelScraperDetails); panelScraperDetails .setLayout(new FormLayout(new ColumnSpec[] { ColumnSpec.decode("default:grow"), }, new RowSpec[] { FormSpecs.DEFAULT_ROWSPEC, FormSpecs.UNRELATED_GAP_ROWSPEC, FormSpecs.DEFAULT_ROWSPEC, })); { // add a CSS rule to force body tags to use the default label font // instead of the value in javax.swing.text.html.default.csss Font font = UIManager.getFont("Label.font"); String bodyRule = "body { font-family: " + font.getFamily() + "; " + "font-size: " + font.getSize() + "pt; }"; tpScraperDescription = new JTextPane(); tpScraperDescription.setOpaque(false); tpScraperDescription.setEditorKit(new HTMLEditorKit()); ((HTMLDocument) tpScraperDescription.getDocument()).getStyleSheet().addRule(bodyRule); panelScraperDetails.add(tpScraperDescription, "1, 1, default, top"); } panelScraperOptions = new JPanel(); panelScraperOptions.setLayout(new FlowLayout(FlowLayout.LEFT)); panelScraperDetails.add(panelScraperOptions, "1, 3, fill, top"); JSeparator separator = new JSeparator(); panelMovieScrapers.add(separator, "2, 4, 3, 1"); JLabel lblScraperLanguage = new JLabel(BUNDLE.getString("Settings.preferredLanguage")); //$NON-NLS-1$ panelMovieScrapers.add(lblScraperLanguage, "2, 5, right, default"); cbScraperLanguage = new JComboBox(MediaLanguages.values()); panelMovieScrapers.add(cbScraperLanguage, "4, 5"); JLabel lblCountry = new JLabel(BUNDLE.getString("Settings.certificationCountry")); //$NON-NLS-1$ panelMovieScrapers.add(lblCountry, "2, 7, right, default"); cbCertificationCountry = new JComboBox(CountryCode.values()); panelMovieScrapers.add(cbCertificationCountry, "4, 7, fill, default"); panelMovieScrapers.add(new JSeparator(), "2, 8, 5, 1"); chckbxScraperFallback = new JCheckBox(BUNDLE.getString("Settings.scraperfallback")); //$NON-NLS-1$ panelMovieScrapers.add(chckbxScraperFallback, "2, 9, 5, 1"); panelScraperMetadataContainer = new JPanel(); panelScraperMetadataContainer.setBorder(new TitledBorder(UIManager.getBorder("TitledBorder.border"), BUNDLE.getString("scraper.metadata.defaults"), TitledBorder.LEADING, TitledBorder.TOP, null, //$NON-NLS-1$ new Color(51, 51, 51))); add(panelScraperMetadataContainer, "2, 4, fill, fill"); panelScraperMetadataContainer.setLayout(new FormLayout( new ColumnSpec[] { FormFactory.RELATED_GAP_COLSPEC, ColumnSpec.decode("10dlu"), FormFactory.RELATED_GAP_COLSPEC, ColumnSpec.decode("default:grow"), }, new RowSpec[] { FormFactory.DEFAULT_ROWSPEC, FormFactory.RELATED_GAP_ROWSPEC, FormFactory.DEFAULT_ROWSPEC, FormFactory.NARROW_LINE_GAP_ROWSPEC, FormFactory.DEFAULT_ROWSPEC, FormFactory.RELATED_GAP_ROWSPEC, })); panelScraperMetadata = new MovieScraperMetadataPanel( Settings.getInstance().getMovieScraperMetadataConfig()); panelScraperMetadataContainer.add(panelScraperMetadata, "1, 1, 4, 1, fill, default"); chckbxAutomaticallyScrapeImages = new JCheckBox(BUNDLE.getString("Settings.default.autoscrape")); //$NON-NLS-1$ panelScraperMetadataContainer.add(chckbxAutomaticallyScrapeImages, "2, 3, 3, 1"); chckbxImageLanguage = new JCheckBox(BUNDLE.getString("Settings.default.autoscrape.language"));//$NON-NLS-1$ panelScraperMetadataContainer.add(chckbxImageLanguage, "4, 5"); panelAutomaticScraper = new JPanel(); panelAutomaticScraper.setBorder(new TitledBorder(null, BUNDLE.getString("Settings.automaticscraper"), //$NON-NLS-1$ TitledBorder.LEADING, TitledBorder.TOP, null, null)); add(panelAutomaticScraper, "4, 4, fill, fill"); panelAutomaticScraper.setLayout(new FormLayout( new ColumnSpec[] { FormFactory.DEFAULT_COLSPEC, FormFactory.RELATED_GAP_COLSPEC, ColumnSpec.decode("default:grow"), }, new RowSpec[] { FormFactory.RELATED_GAP_ROWSPEC, FormFactory.DEFAULT_ROWSPEC, FormFactory.RELATED_GAP_ROWSPEC, FormFactory.DEFAULT_ROWSPEC, FormFactory.RELATED_GAP_ROWSPEC, FormFactory.DEFAULT_ROWSPEC, })); JLabel lblScraperTreshold = new JLabel(BUNDLE.getString("Settings.scraperTreshold")); //$NON-NLS-1$ panelAutomaticScraper.add(lblScraperTreshold, "1, 2, default, top"); sliderThreshold = new JSlider(); sliderThreshold.setMinorTickSpacing(5); sliderThreshold.setMajorTickSpacing(10); sliderThreshold.setPaintTicks(true); sliderThreshold.setPaintLabels(true); sliderThreshold.setValue((int) (settings.getScraperThreshold() * 100)); Hashtable<Integer, JLabel> labelTable = new java.util.Hashtable<>(); labelTable.put(100, new JLabel("1.0")); labelTable.put(75, new JLabel("0.75")); labelTable.put(50, new JLabel("0.50")); labelTable.put(25, new JLabel("0.25")); labelTable.put(0, new JLabel("0.0")); sliderThreshold.setLabelTable(labelTable); sliderThreshold.addChangeListener(new ChangeListener() { @Override public void stateChanged(ChangeEvent arg0) { settings.setScraperThreshold(sliderThreshold.getValue() / 100.0); } }); panelAutomaticScraper.add(sliderThreshold, "3, 2"); lblScraperThresholdHint = new JTextPane(); panelAutomaticScraper.add(lblScraperThresholdHint, "1, 6, 3, 1"); lblScraperThresholdHint.setOpaque(false); TmmFontHelper.changeFont(lblScraperThresholdHint, 0.833); lblScraperThresholdHint.setText(BUNDLE.getString("Settings.scraperTreshold.hint")); //$NON-NLS-1$ initDataBindings(); // adjust table columns // Checkbox and Logo shall have minimal width TableColumnResizer.setMaxWidthForColumn(tableScraper, 0, 2); TableColumnResizer.setMaxWidthForColumn(tableScraper, 1, 2); TableColumnResizer.adjustColumnPreferredWidths(tableScraper, 5); // implement listener to simulate button group tableScraper.getModel().addTableModelListener(new TableModelListener() { @Override public void tableChanged(TableModelEvent arg0) { // click on the checkbox if (arg0.getColumn() == 0) { int row = arg0.getFirstRow(); MovieScraper changedScraper = scrapers.get(row); // if flag default scraper was changed, change all other flags if (changedScraper.getDefaultScraper()) { settings.setMovieScraper(changedScraper.getScraperId()); for (MovieScraper scraper : scrapers) { if (scraper != changedScraper) { scraper.setDefaultScraper(Boolean.FALSE); } } } } } }); // implement selection listener to load settings tableScraper.getSelectionModel().addListSelectionListener(new ListSelectionListener() { @Override public void valueChanged(ListSelectionEvent e) { int index = tableScraper.convertRowIndexToModel(tableScraper.getSelectedRow()); if (index > -1) { panelScraperOptions.removeAll(); if (scrapers.get(index).getMediaProvider().getProviderInfo().getConfig().hasConfig()) { panelScraperOptions .add(new MediaScraperConfigurationPanel(scrapers.get(index).getMediaProvider())); } panelScraperOptions.revalidate(); } } }); // select default movie scraper if (counter > 0) { tableScraper.getSelectionModel().setSelectionInterval(selectedIndex, selectedIndex); } }
From source file:org.tinymediamanager.ui.movies.settings.MovieSubtitleSettingsPanel.java
private void initComponents() { // data init/*w ww . j a v a2 s . c o m*/ List<String> enabledSubtitleProviders = settings.getMovieSubtitleScrapers(); int selectedIndex = -1; int counter = 0; for (MediaScraper scraper : MovieList.getInstance().getAvailableSubtitleScrapers()) { SubtitleScraper subtitleScraper = new SubtitleScraper(scraper); if (enabledSubtitleProviders.contains(subtitleScraper.getScraperId())) { subtitleScraper.active = true; if (selectedIndex < 0) { selectedIndex = counter; } } scrapers.add(subtitleScraper); counter++; } // UI init setLayout(new FormLayout( new ColumnSpec[] { FormSpecs.RELATED_GAP_COLSPEC, FormSpecs.DEFAULT_COLSPEC, FormSpecs.RELATED_GAP_COLSPEC, FormSpecs.DEFAULT_COLSPEC, FormSpecs.RELATED_GAP_COLSPEC, ColumnSpec.decode("default:grow"), FormSpecs.RELATED_GAP_COLSPEC, }, new RowSpec[] { FormSpecs.RELATED_GAP_ROWSPEC, RowSpec.decode("default:grow"), FormSpecs.RELATED_GAP_ROWSPEC, FormSpecs.DEFAULT_ROWSPEC, FormSpecs.RELATED_GAP_ROWSPEC, })); JPanel panelSubtitleScrapers = new JPanel(); panelSubtitleScrapers.setBorder(new TitledBorder(UIManager.getBorder("TitledBorder.border"), BUNDLE.getString("scraper.subtitle"), TitledBorder.LEADING, TitledBorder.TOP, null, null)); // $NON-NLS-1$ add(panelSubtitleScrapers, "2, 2, 5, 1, fill, fill"); panelSubtitleScrapers.setLayout(new FormLayout( new ColumnSpec[] { FormSpecs.RELATED_GAP_COLSPEC, ColumnSpec.decode("100dlu:grow"), FormSpecs.RELATED_GAP_COLSPEC, ColumnSpec.decode("200dlu:grow"), FormSpecs.RELATED_GAP_COLSPEC, }, new RowSpec[] { FormSpecs.RELATED_GAP_ROWSPEC, RowSpec.decode("100dlu:grow"), })); final JScrollPane scrollPaneScraperDetails = new JScrollPane(); scrollPaneScraperDetails.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER); scrollPaneScraperDetails.setBorder(null); panelSubtitleScrapers.add(scrollPaneScraperDetails, "4, 1, 1, 2, fill, fill"); JPanel panelScraperDetails = new JPanel(); scrollPaneScraperDetails.setViewportView(panelScraperDetails); panelScraperDetails.setLayout(new FormLayout(new ColumnSpec[] { ColumnSpec.decode("default:grow"), }, new RowSpec[] { RowSpec.decode("default:grow"), FormSpecs.RELATED_GAP_ROWSPEC, FormSpecs.DEFAULT_ROWSPEC, })); { // add a CSS rule to force body tags to use the default label font // instead of the value in javax.swing.text.html.default.csss Font font = UIManager.getFont("Label.font"); String bodyRule = "body { font-family: " + font.getFamily() + "; " + "font-size: " + font.getSize() + "pt; }"; tpScraperDescription = new JTextPane(); tpScraperDescription.setOpaque(false); tpScraperDescription.setEditorKit(new HTMLEditorKit()); ((HTMLDocument) tpScraperDescription.getDocument()).getStyleSheet().addRule(bodyRule); panelScraperDetails.add(tpScraperDescription, "1, 1, fill, top"); } panelScraperOptions = new ScrollablePanel(); panelScraperOptions.setLayout(new FlowLayout(FlowLayout.LEFT)); panelScraperDetails.add(panelScraperOptions, "1, 3, fill, top"); JScrollPane scrollPaneScraper = new JScrollPane(); panelSubtitleScrapers.add(scrollPaneScraper, "2, 2, fill, fill"); tableScraper = new JTable(); tableScraper.setRowHeight(29); scrollPaneScraper.setViewportView(tableScraper); final JLabel lblScraperLanguage = new JLabel(BUNDLE.getString("Settings.preferredLanguage")); //$NON-NLS-1$ add(lblScraperLanguage, "2, 4, right, default"); cbScraperLanguage = new JComboBox(MediaLanguages.values()); add(cbScraperLanguage, "4, 4, fill, default"); initDataBindings(); // adjust table columns // Checkbox and Logo shall have minimal width TableColumnResizer.setMaxWidthForColumn(tableScraper, 0, 2); TableColumnResizer.setMaxWidthForColumn(tableScraper, 1, 2); TableColumnResizer.adjustColumnPreferredWidths(tableScraper, 5); tableScraper.getModel().addTableModelListener(new TableModelListener() { @Override public void tableChanged(TableModelEvent arg0) { // click on the checkbox if (arg0.getColumn() == 0) { int row = arg0.getFirstRow(); SubtitleScraper changedScraper = scrapers.get(row); if (changedScraper.active) { settings.addMovieSubtitleScraper(changedScraper.getScraperId()); } else { settings.removeMovieSubtitleScraper(changedScraper.getScraperId()); } } } }); // implement selection listener to load settings tableScraper.getSelectionModel().addListSelectionListener(new ListSelectionListener() { @Override public void valueChanged(ListSelectionEvent e) { int index = tableScraper.convertRowIndexToModel(tableScraper.getSelectedRow()); if (index > -1) { panelScraperOptions.removeAll(); if (scrapers.get(index).getMediaProvider().getProviderInfo().getConfig().hasConfig()) { panelScraperOptions .add(new MediaScraperConfigurationPanel(scrapers.get(index).getMediaProvider())); } panelScraperOptions.revalidate(); } } }); // select default movie scraper if (selectedIndex < 0) { selectedIndex = 0; } if (counter > 0) { tableScraper.getSelectionModel().setSelectionInterval(selectedIndex, selectedIndex); } }
From source file:org.tinymediamanager.ui.movies.settings.MovieTrailerSettingsPanel.java
public MovieTrailerSettingsPanel() { // data init//from w ww .ja v a 2s.c o m List<String> enabledTrailerProviders = settings.getMovieTrailerScrapers(); int selectedIndex = -1; int counter = 0; for (MediaScraper scraper : MovieList.getInstance().getAvailableTrailerScrapers()) { TrailerScraper trailerScraper = new TrailerScraper(scraper); if (enabledTrailerProviders.contains(trailerScraper.getScraperId())) { trailerScraper.active = true; if (selectedIndex < 0) { selectedIndex = counter; } } scrapers.add(trailerScraper); counter++; } // UI init setLayout(new FormLayout( new ColumnSpec[] { FormSpecs.RELATED_GAP_COLSPEC, ColumnSpec.decode("default:grow"), FormSpecs.RELATED_GAP_COLSPEC, }, new RowSpec[] { FormSpecs.RELATED_GAP_ROWSPEC, RowSpec.decode("default:grow"), FormSpecs.RELATED_GAP_ROWSPEC, })); JPanel panelTrailerScrapers = new JPanel(); panelTrailerScrapers.setBorder(new TitledBorder(UIManager.getBorder("TitledBorder.border"), BUNDLE.getString("scraper.trailer"), TitledBorder.LEADING, TitledBorder.TOP, null, null)); // $NON-NLS-1$ add(panelTrailerScrapers, "2, 2, fill, fill"); panelTrailerScrapers.setLayout(new FormLayout( new ColumnSpec[] { FormSpecs.RELATED_GAP_COLSPEC, FormSpecs.UNRELATED_GAP_COLSPEC, FormSpecs.RELATED_GAP_COLSPEC, FormSpecs.DEFAULT_COLSPEC, FormSpecs.RELATED_GAP_COLSPEC, ColumnSpec.decode("default:grow"), FormSpecs.RELATED_GAP_COLSPEC, ColumnSpec.decode("200dlu:grow"), FormSpecs.RELATED_GAP_COLSPEC, }, new RowSpec[] { FormSpecs.RELATED_GAP_ROWSPEC, RowSpec.decode("100dlu:grow"), FormSpecs.RELATED_GAP_ROWSPEC, FormSpecs.DEFAULT_ROWSPEC, FormSpecs.RELATED_GAP_ROWSPEC, FormSpecs.DEFAULT_ROWSPEC, FormSpecs.LABEL_COMPONENT_GAP_ROWSPEC, FormSpecs.DEFAULT_ROWSPEC, FormSpecs.LABEL_COMPONENT_GAP_ROWSPEC, FormSpecs.DEFAULT_ROWSPEC, FormSpecs.UNRELATED_GAP_ROWSPEC, FormSpecs.DEFAULT_ROWSPEC, FormSpecs.LABEL_COMPONENT_GAP_ROWSPEC, FormSpecs.DEFAULT_ROWSPEC, FormSpecs.RELATED_GAP_ROWSPEC, })); final JScrollPane scrollPaneScraperDetails = new JScrollPane(); scrollPaneScraperDetails.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER); scrollPaneScraperDetails.setBorder(null); panelTrailerScrapers.add(scrollPaneScraperDetails, "8, 1, 1, 2, fill, fill"); JPanel panelScraperDetails = new JPanel(); scrollPaneScraperDetails.setViewportView(panelScraperDetails); panelScraperDetails.setLayout(new FormLayout(new ColumnSpec[] { ColumnSpec.decode("default:grow"), }, new RowSpec[] { RowSpec.decode("default:grow"), FormSpecs.RELATED_GAP_ROWSPEC, FormSpecs.DEFAULT_ROWSPEC, })); { // add a CSS rule to force body tags to use the default label font // instead of the value in javax.swing.text.html.default.csss Font font = UIManager.getFont("Label.font"); String bodyRule = "body { font-family: " + font.getFamily() + "; " + "font-size: " + font.getSize() + "pt; }"; tpScraperDescription = new JTextPane(); tpScraperDescription.setOpaque(false); tpScraperDescription.setEditorKit(new HTMLEditorKit()); ((HTMLDocument) tpScraperDescription.getDocument()).getStyleSheet().addRule(bodyRule); panelScraperDetails.add(tpScraperDescription, "1, 1, fill, top"); } panelScraperOptions = new ScrollablePanel(); panelScraperOptions.setLayout(new FlowLayout(FlowLayout.LEFT)); panelScraperDetails.add(panelScraperOptions, "1, 3, fill, top"); JScrollPane scrollPaneScraper = new JScrollPane(); panelTrailerScrapers.add(scrollPaneScraper, "2, 2, 5, 1, fill, fill"); tableTrailerScraper = new JTable(); tableTrailerScraper.setRowHeight(29); scrollPaneScraper.setViewportView(tableTrailerScraper); JSeparator separator = new JSeparator(); panelTrailerScrapers.add(separator, "2, 4, 7, 1"); checkBox = new JCheckBox(BUNDLE.getString("Settings.trailer.preferred")); //$NON-NLS-1$ panelTrailerScrapers.add(checkBox, "2, 6, 7, 1"); JLabel lblTrailerSource = new JLabel(BUNDLE.getString("Settings.trailer.source")); //$NON-NLS-1$ panelTrailerScrapers.add(lblTrailerSource, "4, 8, right, default"); cbTrailerSource = new JComboBox<>(); cbTrailerSource.setModel(new DefaultComboBoxModel<>(MovieTrailerSources.values())); panelTrailerScrapers.add(cbTrailerSource, "6, 8, fill, default"); JLabel lblTrailerQuality = new JLabel(BUNDLE.getString("Settings.trailer.quality")); //$NON-NLS-1$ panelTrailerScrapers.add(lblTrailerQuality, "4, 10, right, default"); cbTrailerQuality = new JComboBox<>(); cbTrailerQuality.setModel(new DefaultComboBoxModel<>(MovieTrailerQuality.values())); panelTrailerScrapers.add(cbTrailerQuality, "6, 10, fill, default"); chckbxAutomaticTrailerDownload = new JCheckBox(BUNDLE.getString("Settings.trailer.automaticdownload")); //$NON-NLS-1$ panelTrailerScrapers.add(chckbxAutomaticTrailerDownload, "2, 12, 7, 1"); JLabel lblAutomaticTrailerDownloadHint = new JLabel( BUNDLE.getString("Settings.trailer.automaticdownload.hint")); //$NON-NLS-1$ TmmFontHelper.changeFont(lblAutomaticTrailerDownloadHint, 0.833); panelTrailerScrapers.add(lblAutomaticTrailerDownloadHint, "4, 14, 5, 1"); initDataBindings(); // adjust table columns // Checkbox and Logo shall have minimal width TableColumnResizer.setMaxWidthForColumn(tableTrailerScraper, 0, 2); TableColumnResizer.setMaxWidthForColumn(tableTrailerScraper, 1, 2); TableColumnResizer.adjustColumnPreferredWidths(tableTrailerScraper, 5); tableTrailerScraper.getModel().addTableModelListener(new TableModelListener() { @Override public void tableChanged(TableModelEvent arg0) { // click on the checkbox if (arg0.getColumn() == 0) { int row = arg0.getFirstRow(); TrailerScraper changedScraper = scrapers.get(row); if (changedScraper.active) { settings.addMovieTrailerScraper(changedScraper.getScraperId()); } else { settings.removeMovieTrailerScraper(changedScraper.getScraperId()); } } } }); // implement selection listener to load settings tableTrailerScraper.getSelectionModel().addListSelectionListener(new ListSelectionListener() { @Override public void valueChanged(ListSelectionEvent e) { int index = tableTrailerScraper.convertRowIndexToModel(tableTrailerScraper.getSelectedRow()); if (index > -1) { panelScraperOptions.removeAll(); if (scrapers.get(index).getMediaProvider().getProviderInfo().getConfig().hasConfig()) { panelScraperOptions .add(new MediaScraperConfigurationPanel(scrapers.get(index).getMediaProvider())); } panelScraperOptions.revalidate(); } } }); // select default movie scraper if (selectedIndex < 0) { selectedIndex = 0; } if (counter > 0) { tableTrailerScraper.getSelectionModel().setSelectionInterval(selectedIndex, selectedIndex); } }