📄 jcatalog.java
字号:
// Tina POS is a point of sales application designed for touch screens.// Copyright (C) 2005 Adrian Romero Corchado.// http://sourceforge.net/projects/tinapos//// This program is free software; you can redistribute it and/or modify// it under the terms of the GNU General Public License as published by// the Free Software Foundation; either version 2 of the License, or// (at your option) any later version.//// This program is distributed in the hope that it will be useful,// but WITHOUT ANY WARRANTY; without even the implied warranty of// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the// GNU General Public License for more details.//// You should have received a copy of the GNU General Public License// along with this program; if not, write to the Free Software// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USApackage net.adrianromero.tpv.panels;import net.adrianromero.tpv.ticket.*;import net.adrianromero.tpv.util.ThumbNailBuilder;import java.util.*;import javax.swing.*;import javax.swing.event.*;import java.awt.event.*;import java.awt.*;import javax.imageio.ImageIO;import net.adrianromero.tpv.forms.AppView;import net.adrianromero.tpv.forms.AppLocal;import net.adrianromero.basic.BasicException;import net.adrianromero.data.loader.SentenceList;import net.adrianromero.data.loader.SentenceFind;import net.adrianromero.tpv.forms.SentenceContainer;import net.adrianromero.tpv.ticket.ThumbNailBuilderProduct;public class JCatalog extends JPanel implements ListSelectionListener { protected EventListenerList listeners = new EventListenerList(); private AppView m_App; // Listado de paneles de productos modificadores... private Set m_productcom = new HashSet(); private Set m_productcomEmpty = new HashSet(); // Listado de productos en memoria... private Map m_productcache = new HashMap(); private ThumbNailBuilderProduct tnbprodtext; /** Creates new form JCatalog */ public JCatalog(AppView oApp) { this(oApp, ThumbNailBuilderProduct.PRICE_NONE); } public JCatalog(AppView oApp, int iPriceMode) { m_App = oApp; initComponents(); Image defimg; try { defimg = ImageIO.read(getClass().getClassLoader().getResourceAsStream("net/adrianromero/images/colorize.png")); } catch (Exception fnfe) { defimg = null; } tnbprodtext = new ThumbNailBuilderProduct(64, 32, defimg, iPriceMode); m_jListCategories.addListSelectionListener(this); m_jscrollcat.getVerticalScrollBar().setPreferredSize(new Dimension(35, 35)); } private ProductInfoExt getProduct(String reference) { if (m_productcache.containsKey(reference)) { return (ProductInfoExt) m_productcache.get(reference); } else { ProductInfoExt p; try { p = m_App.lookupDataLogic(SentenceContainer.class).getProductInfo2(reference); } catch (BasicException eb) { p = null; // nunca pasa ;-) } m_productcache.put(reference, p); return p; } } public void loadProduct(String reference) { if (reference == null) { showCatalogPanel(); } else { String smypanel = "." + reference; // Si ya existia y estaba vacio, mostramos el catalogo general if (m_productcomEmpty.contains(reference)) { showCatalogPanel(); } else if (m_productcom.contains(reference)) { // existia, y tenia productos, lo muestro. showCommentPanel(smypanel); } else { try { java.util.List<ProductInfoExt> products = m_App.lookupDataLogic(SentenceContainer.class).getProductComments(reference); if (products.size() == 0) { // no hay productos por tanto lo anado a la de vacios y muestro el panel principal. m_productcomEmpty.add(reference); showCatalogPanel(); } else { // creo un nuevo panel de productos... JCatalogCom jprodcom = new JCatalogCom(getProduct(reference), new BackAction()); for (ProductInfoExt prod : products) { jprodcom.addProduct(tnbprodtext.getThumbNail(prod), prod.getName(), new SelectedAction(prod)); } m_productcom.add(smypanel); m_jProductSingle.add(smypanel, jprodcom); showCommentPanel(smypanel); } } catch (BasicException eb) { // fallo la ejecucion de la lista de productos. // nunca deberia ocurrir. eb.printStackTrace(); m_productcomEmpty.add(reference); showCatalogPanel(); } } } } public void loadCatalog() throws BasicException { // borro lo que ya habiamos creado... m_jProducts.removeAll(); m_productcache = new HashMap(); m_productcom = new HashSet(); m_productcomEmpty = new HashSet(); m_jProductSingle.removeAll(); // SentenceList sent = m_App.lookupDataLogic(SentenceContainer.class).getProductCatalog(); // SentenceList catlist = m_App.lookupDataLogic(SentenceContainer.class).getCategoryList(); java.util.List<ProductInfoExt> products = m_App.lookupDataLogic(SentenceContainer.class).getProductCatalog(); java.util.List<CategoryInfo> categories = m_App.lookupDataLogic(SentenceContainer.class).getCategoryList(); int iIndexCat = 0; Image defimg; try { defimg = ImageIO.read(getClass().getClassLoader().getResourceAsStream("net/adrianromero/images/colorize.png")); } catch (Exception fnfe) { defimg = null; } ThumbNailBuilder tnbcat = new ThumbNailBuilder(32, 32, defimg); Integer categoryID = null; JCatalogTab jcurrTab = null; JCatalogTab jnullTab = null; java.util.List aCatList = new ArrayList(); for (int i = 0; i < products.size(); i++) { ProductInfoExt prod = products.get(i); if (jcurrTab == null || ((categoryID == null && prod.getCategoryID() != null) || !categoryID.equals(prod.getCategoryID()))) { // Buscamos la categoria del producto CategoryInfo newcat = null; if (prod.getCategoryID() != null) { CategoryInfo searchcat = null; while (iIndexCat < categories.size()) { searchcat = categories.get(iIndexCat++); if (searchcat.getID().equals(prod.getCategoryID())) { newcat = searchcat; break; } } } if (newcat == null) { if (jnullTab == null) { jnullTab = new JCatalogTab(); } jcurrTab = jnullTab; categoryID = prod.getCategoryID(); } else { jcurrTab = new JCatalogTab(); categoryID = newcat.getID(); m_jProducts.add(jcurrTab, newcat.getID().toString()); // m_jTabCategories.addTab(newcat.getName(), new ImageIcon(tnbcat.getThumbNail(newcat.getImage())), jcurrTab); aCatList.add(new Object[] {newcat.getID(), newcat.getName(), new ImageIcon(tnbcat.getThumbNail(newcat.getImage()))}); } } jcurrTab.addProduct(tnbprodtext.getThumbNail(prod), prod.getName(), new SelectedAction(prod)); } // Si ha habido productos del catalogo sin categoria. if (jnullTab != null) { m_jProducts.add(jnullTab, Integer.toString(Integer.MIN_VALUE)); // m_jTabCategories.addTab(AppLocal.getIntString("label.nullcategory"), new ImageIcon(tnbcat.getThumbNail(null)), jnullTab); aCatList.add(new Object[] {new Integer(Integer.MIN_VALUE), AppLocal.getIntString("label.nullcategory"), new ImageIcon(tnbcat.getThumbNail(null))}); } m_jListCategories.setCellRenderer(new SmallCategoryRenderer()); m_jListCategories.setModel(new CategoriesListModel(aCatList)); if (m_jListCategories.getModel().getSize() > 0) { m_jListCategories.setSelectedIndex(0); } showCatalogPanel(); } public void setEnabled(boolean value) { m_jListCategories.setEnabled(value); m_jscrollcat.setEnabled(value); m_jUp.setEnabled(value); m_jDown.setEnabled(value); m_jProducts.setEnabled(value); synchronized (m_jProducts.getTreeLock()) { int compCount = m_jProducts.getComponentCount(); for (int i = 0 ; i < compCount ; i++) { m_jProducts.getComponent(i).setEnabled(value); } } super.setEnabled(value); } public void addActionListener(ActionListener l) { listeners.add(ActionListener.class, l); } public void removeActionListener(ActionListener l) { listeners.add(ActionListener.class, l);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -