private JPanel getRemoveOptionsPanel() { if (pnlRemoveOptions == null) { pnlRemoveOptions = new JPanel(new BorderLayout()); DefaultBeanInfoResolver resolver = new DefaultBeanInfoResolver(); BeanInfo beanInfo = resolver.getBeanInfo(options); PropertySheetPanel sheet = new PropertySheetPanel(); sheet.setMode(PropertySheet.VIEW_AS_CATEGORIES); sheet.setProperties(beanInfo.getPropertyDescriptors()); sheet.readFromObject(options); sheet.setDescriptionVisible(true); sheet.setSortingCategories(true); sheet.setSortingProperties(true); pnlRemoveOptions.add(sheet, BorderLayout.CENTER); // everytime a property change, update the button with it PropertyChangeListener listener = new PropertyChangeListener() { public void propertyChange(PropertyChangeEvent evt) { Property prop = (Property) evt.getSource(); prop.writeToObject(options); } }; sheet.addPropertySheetChangeListener(listener); } return pnlRemoveOptions; }
public PropertySheetApplicationStats() { setLayout(LookAndFeelTweaks.createVerticalPercentLayout()); final Bean data = new Bean(); TimeSpan timespan = null; // counts of objects long discCount = HibernateDao.countAll(Disc.class); data.setCountArtists(Long.toString(HibernateDao.countAll(Artist.class))); data.setCountDiscs(Long.toString(discCount)); data.setCountTracks(Long.toString(HibernateDao.countAll(Track.class))); // time stats long totalTime = 0; long totalSize = 0; long avgTimePerDisc = 0; long avgSizePerDisc = 0; try { totalTime = HibernateDao.sum(Disc.class, Disc.PROPERTYNAME_DURATION); totalSize = HibernateDao.sum(Track.class, Track.PROPERTYNAME_TRACK_SIZE); avgTimePerDisc = (totalTime / discCount) * 1000; avgSizePerDisc = (totalSize / discCount); } catch (RuntimeException ex) { totalTime = 0; } // calculate time fields to display properly timespan = new TimeSpan(totalTime * 1000); data.setTimeTotal(timespan.toString()); timespan = new TimeSpan(avgTimePerDisc); data.setTimeAveragePerDisc(timespan.toString()); // file stats data.setFileTotal(FileUtils.byteCountToDisplaySize(totalSize)); data.setFileAveragePerDisc(FileUtils.byteCountToDisplaySize(avgSizePerDisc)); DefaultBeanInfoResolver resolver = new DefaultBeanInfoResolver(); BeanInfo beanInfo = resolver.getBeanInfo(data); PropertySheetPanel sheet = new PropertySheetPanel(); sheet.setMode(PropertySheet.VIEW_AS_CATEGORIES); sheet.setProperties(beanInfo.getPropertyDescriptors()); sheet.readFromObject(data); sheet.setDescriptionVisible(true); sheet.setSortingCategories(true); sheet.setSortingProperties(true); add(sheet, "*"); // everytime a property change, update the button with it PropertyChangeListener listener = new PropertyChangeListener() { public void propertyChange(PropertyChangeEvent evt) { Property prop = (Property) evt.getSource(); prop.writeToObject(data); } }; sheet.addPropertySheetChangeListener(listener); }