📄 jcatalog.java
字号:
} public void valueChanged(ListSelectionEvent evt) { if (!evt.getValueIsAdjusting()) { int i = m_jListCategories.getSelectedIndex(); if (i >= 0) { // Lo hago visible... Rectangle oRect = m_jListCategories.getCellBounds(i, i); m_jListCategories.scrollRectToVisible(oRect); } } } protected void fireSelectedProduct(ProductInfoExt prod) { EventListener[] l = listeners.getListeners(ActionListener.class); ActionEvent e = null; for (int i = 0; i < l.length; i++) { if (e == null) { e = new ActionEvent(prod, ActionEvent.ACTION_PERFORMED, prod.getReference()); } ((ActionListener) l[i]).actionPerformed(e); } } private void showCommentPanel(String view) { CardLayout cl = (CardLayout)(this.getLayout()); cl.show(this, "comment"); cl = (CardLayout)(this.getLayout()); cl.show(this, view); } private void showCatalogPanel() { CardLayout cl = (CardLayout)(this.getLayout()); cl.show(this, "catalog"); } private void showProductsPanel(String view) { CardLayout cl = (CardLayout)(m_jProducts.getLayout()); cl.show(m_jProducts, view); } private class SelectedAction implements ActionListener { private ProductInfoExt prod; public SelectedAction(ProductInfoExt prod) { this.prod = prod; } public void actionPerformed(ActionEvent e) { fireSelectedProduct(prod); } } private class BackAction implements ActionListener { public void actionPerformed(ActionEvent e) { showCatalogPanel(); } } private class CategoriesListModel extends AbstractListModel { private java.util.List m_aCategories; public CategoriesListModel(java.util.List aCategories) { m_aCategories = aCategories; } public int getSize() { return m_aCategories.size(); } public Object getElementAt(int i) { return m_aCategories.get(i); } } private class SmallCategoryRenderer extends DefaultListCellRenderer { public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { super.getListCellRendererComponent(list, null, index, isSelected, cellHasFocus); Object[] cat = (Object[]) value; setText((String) cat[1]); setIcon((Icon) cat[2]); return this; } } /** This method is called from within the constructor to * initialize the form. * WARNING: Do NOT modify this code. The content of this method is * always regenerated by the Form Editor. */ // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents private void initComponents() { m_jCatalogAll = new javax.swing.JPanel(); jPanel1 = new javax.swing.JPanel(); m_jscrollcat = new javax.swing.JScrollPane(); m_jListCategories = new javax.swing.JList(); jPanel2 = new javax.swing.JPanel(); jPanel3 = new javax.swing.JPanel(); m_jUp = new javax.swing.JButton(); m_jDown = new javax.swing.JButton(); m_jProducts = new javax.swing.JPanel(); m_jProductSingle = new javax.swing.JPanel(); setLayout(new java.awt.CardLayout()); setBorder(javax.swing.BorderFactory.createEmptyBorder(5, 5, 5, 5)); m_jCatalogAll.setLayout(new java.awt.BorderLayout()); jPanel1.setLayout(new java.awt.BorderLayout()); m_jscrollcat.setHorizontalScrollBarPolicy(javax.swing.ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER); m_jscrollcat.setVerticalScrollBarPolicy(javax.swing.ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS); m_jscrollcat.setPreferredSize(new java.awt.Dimension(235, 0)); m_jListCategories.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION); m_jListCategories.setFocusable(false); m_jListCategories.addListSelectionListener(new javax.swing.event.ListSelectionListener() { public void valueChanged(javax.swing.event.ListSelectionEvent evt) { m_jListCategoriesValueChanged(evt); } }); m_jscrollcat.setViewportView(m_jListCategories); jPanel1.add(m_jscrollcat, java.awt.BorderLayout.WEST); jPanel2.setLayout(new java.awt.BorderLayout()); jPanel3.setLayout(new java.awt.GridLayout(0, 1, 0, 5)); jPanel3.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 5, 0, 5)); m_jUp.setIcon(new javax.swing.ImageIcon(getClass().getResource("/net/adrianromero/images/1uparrow.png"))); m_jUp.setFocusPainted(false); m_jUp.setFocusable(false); m_jUp.setMargin(new java.awt.Insets(8, 14, 8, 14)); m_jUp.setRequestFocusEnabled(false); m_jUp.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { m_jUpActionPerformed(evt); } }); jPanel3.add(m_jUp); m_jDown.setIcon(new javax.swing.ImageIcon(getClass().getResource("/net/adrianromero/images/1downarrow.png"))); m_jDown.setFocusPainted(false); m_jDown.setFocusable(false); m_jDown.setMargin(new java.awt.Insets(8, 14, 8, 14)); m_jDown.setRequestFocusEnabled(false); m_jDown.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { m_jDownActionPerformed(evt); } }); jPanel3.add(m_jDown); jPanel2.add(jPanel3, java.awt.BorderLayout.NORTH); jPanel1.add(jPanel2, java.awt.BorderLayout.CENTER); m_jCatalogAll.add(jPanel1, java.awt.BorderLayout.WEST); m_jProducts.setLayout(new java.awt.CardLayout()); m_jProducts.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 5, 0, 0)); m_jCatalogAll.add(m_jProducts, java.awt.BorderLayout.CENTER); add(m_jCatalogAll, "catalog"); m_jProductSingle.setLayout(new java.awt.CardLayout()); add(m_jProductSingle, "comment"); }// </editor-fold>//GEN-END:initComponents private void m_jDownActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_m_jDownActionPerformed int i = m_jListCategories.getSelectionModel().getMaxSelectionIndex(); if (i < 0){ i = 0; // No hay ninguna seleccionada } else { i ++; if (i >= m_jListCategories.getModel().getSize() ) { i = m_jListCategories.getModel().getSize() - 1; } } if ((i >= 0) && (i < m_jListCategories.getModel().getSize())) { // Solo seleccionamos si podemos. m_jListCategories.getSelectionModel().setSelectionInterval(i, i); } }//GEN-LAST:event_m_jDownActionPerformed private void m_jUpActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_m_jUpActionPerformed int i = m_jListCategories.getSelectionModel().getMinSelectionIndex(); if (i < 0){ i = m_jListCategories.getModel().getSize() - 1; // No hay ninguna seleccionada } else { i --; if (i < 0) { i = 0; } } if ((i >= 0) && (i < m_jListCategories.getModel().getSize())) { // Solo seleccionamos si podemos. m_jListCategories.getSelectionModel().setSelectionInterval(i, i); } }//GEN-LAST:event_m_jUpActionPerformed private void m_jListCategoriesValueChanged(javax.swing.event.ListSelectionEvent evt) {//GEN-FIRST:event_m_jListCategoriesValueChanged if (!evt.getValueIsAdjusting()) { Object[] i = (Object[]) m_jListCategories.getSelectedValue(); if (i != null) { showProductsPanel(((Integer) i[0]).toString()); } } }//GEN-LAST:event_m_jListCategoriesValueChanged // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JPanel jPanel1; private javax.swing.JPanel jPanel2; private javax.swing.JPanel jPanel3; private javax.swing.JPanel m_jCatalogAll; private javax.swing.JButton m_jDown; private javax.swing.JList m_jListCategories; private javax.swing.JPanel m_jProductSingle; private javax.swing.JPanel m_jProducts; private javax.swing.JButton m_jUp; private javax.swing.JScrollPane m_jscrollcat; // End of variables declaration//GEN-END:variables }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -