private void findPropertiesCreateNodeUpdateNodeList( PropertiesProvider subPanel, ArrayList<DefaultMutableTreeNode> unsortedNodes) { // find properties PropertySheetPanel propertiesPanel = createPropertiesPanelForClass(subPanel); // create node and update tree if (propertiesPanel.getPropertyCount() > 0) { unsortedNodes.add(createNode(subPanel, propertiesPanel)); } }
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); }
/** * Cycle through the nodes in the new model.<br> * For each node in the old model that also had a panel, create (for the new permission level) and * transfer all the properties in the old one that are still present. <br> * As panel is only created if is visualized, this guarantees that all previously modified * properties keep modifications. * * @param oldProps properties inserted in the old model * @param newModel set the old properties in the new model */ private void updateUsedPanels(HashMap<String, Property[]> oldProps, DefaultTreeModel newModel) { DefaultMutableTreeNode root = (DefaultMutableTreeNode) newModel.getRoot(); int childCount = newModel.getChildCount(root); DefaultMutableTreeNode node; ClassPropertiesInfo funcInfo; Property[] storedProps; for (int i = 0; i < childCount; i++) { node = (DefaultMutableTreeNode) newModel.getChild(root, i); funcInfo = (ClassPropertiesInfo) node.getUserObject(); storedProps = oldProps.get(funcInfo.getName()); // If this functionality was viewed it might contain changes if (storedProps != null) { // Create panel for it PropertySheetPanel propertyPanel = createPropertiesPanelForClass(funcInfo.getClassInstance()); Property newProps[] = propertyPanel.getProperties(); // go through properties int newPropsLength = newProps.length; int storedPropsLength = storedProps.length; // find who has more properties if (newPropsLength < storedPropsLength) { // lowering the permission int pStored = 0; int pNew = 0; while (pNew < newPropsLength && pStored < storedPropsLength) { if (storedProps[pStored].getName().equals(newProps[pNew].getName())) { newProps[pNew].setValue(storedProps[pStored].getValue()); pNew++; } pStored++; } } else { // going to higher permission int pStored = 0; int pNew = 0; while (pNew < newPropsLength && pStored < storedPropsLength) { if (storedProps[pStored].getName().equals(newProps[pNew].getName())) { newProps[pNew].setValue(storedProps[pStored].getValue()); pStored++; } pNew++; } } // set the updated properties panel funcInfo.setPropertiesPanel(propertyPanel); } } }
public void saveChanges() { TreeModel model = tree.getModel(); Object root = model.getRoot(); ClassPropertiesInfo classInfo; int classCount = model.getChildCount(root); for (int c = 0; c < classCount; c++) { classInfo = (ClassPropertiesInfo) ((DefaultMutableTreeNode) model.getChild(root, c)).getUserObject(); PropertySheetPanel propertiesPanel = classInfo.getPropertiesPanel(); if (propertiesPanel != null) { // to exit edit mode and retrieve the value propertiesPanel.getTable().commitEditing(); setProperties(classInfo); } } GeneralPreferences.saveProperties(); }
private HashMap<String, Property[]> extractProperties(TreeModel model) { HashMap<String, Property[]> props = new HashMap<>(); DefaultMutableTreeNode classNode; Object root = model.getRoot(); ClassPropertiesInfo classInfo; int classCount = model.getChildCount(root); Property[] classProperties; for (int c = 0; c < classCount; c++) { classNode = (DefaultMutableTreeNode) model.getChild(root, c); classInfo = (ClassPropertiesInfo) classNode.getUserObject(); PropertySheetPanel propertiesPanel = classInfo.getPropertiesPanel(); if (propertiesPanel != null) { // force out of edit mode propertiesPanel.getTable().commitEditing(); classProperties = propertiesPanel.getProperties(); props.put(classInfo.getName(), classProperties.clone()); } } return props; }
private <T> PropertySheetPanel createPropertiesPanelForClass(PropertiesProvider funcClass) { initEditorRegistry(); initRenderRegistry(); final PropertySheetPanel propertiesPanel = new PropertySheetPanel(); propertiesPanel.setEditorFactory(pEditorRegistry); propertiesPanel.setRendererFactory(pRenderRegistry); propertiesPanel.setMode(PropertySheet.VIEW_AS_CATEGORIES); propertiesPanel.setSortingCategories(true); propertiesPanel.setDescriptionVisible(true); propertiesPanel.setSorting(true); propertiesPanel.setToolBarVisible(false); NeptusProperty neptusProperty = null; LEVEL userLevel; // for (Field f : funcClass.getClass().getFields()) { for (Field f : funcClass.getClass().getDeclaredFields()) { neptusProperty = f.getAnnotation(NeptusProperty.class); if (neptusProperty == null) continue; f.setAccessible(true); // To be able to access private and protected NeptusProperties // CLIENT / DEVELOPER if (clientConsole && neptusProperty.distribution() == DistributionEnum.DEVELOPER) continue; // ADVANCED / REGULAR userLevel = neptusProperty.userLevel(); if (permissionLvl.getLevel() < userLevel.getLevel()) continue; PluginProperty pp; try { pp = extractPluginProperty(f, funcClass); } catch (Exception e) { NeptusLog.pub().error(funcClass.getClass().getSimpleName() + "." + f.getName(), e); throw e; } if (pp != null) propertiesPanel.addProperty(pp); } return propertiesPanel; }
@SuppressWarnings("serial") private void initComponents() { mainSplitPane = new JSplitPane(); mainSplitPane.setBorder(BorderFactory.createEmptyBorder()); listSplitPane = new JSplitPane(); listSplitPane.setBorder(BorderFactory.createEmptyBorder()); bottomPanel = new JPanel(); defaultViewImagePanel = new JPanel(); propertySheetPanel.setTable(new VizMapPropertySheetTable()); vsSelectPanel = new JPanel(); buttonPanel = new JPanel(); initializeVisualStyleComboBox(); optionButton = new DropDownMenuButton( new AbstractAction() { public void actionPerformed(ActionEvent ae) { DropDownMenuButton b = (DropDownMenuButton) ae.getSource(); menuMgr.getMainMenu().show(b, 0, b.getHeight()); } }); GridBagLayout gridbag = new GridBagLayout(); GridBagConstraints constraints = new GridBagConstraints(); buttonPanel.setLayout(gridbag); constraints.gridx = 0; constraints.gridy = 0; constraints.gridwidth = 1; constraints.gridheight = GridBagConstraints.REMAINDER; addButton = new JButton(); addButton.setUI(new BlueishButtonUI()); gridbag.setConstraints(addButton, constraints); buttonPanel.add(addButton); constraints.gridx = 2; constraints.gridy = 0; mainSplitPane.setDividerLocation(160); mainSplitPane.setDividerSize(4); // TODO why do we have to do this? mainSplitPane.setSize(new Dimension(100, 160)); listSplitPane.setDividerLocation(400); listSplitPane.setDividerSize(5); listSplitPane.setOrientation(JSplitPane.VERTICAL_SPLIT); // Default View Panel // defaultViewImagePanel.setMinimumSize(new Dimension(200, 200)); defaultViewImagePanel.setPreferredSize( new Dimension(mainSplitPane.getWidth(), mainSplitPane.getDividerLocation())); defaultViewImagePanel.setSize(defaultViewImagePanel.getPreferredSize()); defaultViewImagePanel.setLayout(new BorderLayout()); noMapListScrollPane = new JScrollPane(); noMapListScrollPane.setBorder( BorderFactory.createTitledBorder( null, "Unused Visual Properties", TitledBorder.CENTER, TitledBorder.DEFAULT_POSITION, new Font("SansSerif", 1, 12))); noMapListScrollPane.setToolTipText("To Create New Mapping, Drag & Drop List Item to Browser."); GroupLayout bottomPanelLayout = new GroupLayout(bottomPanel); bottomPanel.setLayout(bottomPanelLayout); bottomPanelLayout.setHorizontalGroup( bottomPanelLayout .createParallelGroup(GroupLayout.Alignment.LEADING) .addComponent(noMapListScrollPane, GroupLayout.DEFAULT_SIZE, 272, Short.MAX_VALUE) .addComponent( buttonPanel, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)); bottomPanelLayout.setVerticalGroup( bottomPanelLayout .createParallelGroup(GroupLayout.Alignment.LEADING) .addGroup( bottomPanelLayout .createSequentialGroup() .addComponent( buttonPanel, GroupLayout.PREFERRED_SIZE, 25, GroupLayout.PREFERRED_SIZE) .addComponent( noMapListScrollPane, GroupLayout.DEFAULT_SIZE, 135, Short.MAX_VALUE))); listSplitPane.setLeftComponent(mainSplitPane); listSplitPane.setRightComponent(bottomPanel); mainSplitPane.setOrientation(JSplitPane.VERTICAL_SPLIT); defaultViewImagePanel.setBorder( BorderFactory.createTitledBorder( null, "Defaults (Click to edit)", TitledBorder.DEFAULT_JUSTIFICATION, TitledBorder.DEFAULT_POSITION, new Font("SansSerif", 1, 12), Color.darkGray)); mainSplitPane.setLeftComponent(defaultViewImagePanel); propertySheetPanel.setBorder( BorderFactory.createTitledBorder( null, "Visual Mapping Browser", TitledBorder.DEFAULT_JUSTIFICATION, TitledBorder.DEFAULT_POSITION, new Font("SansSerif", 1, 12), Color.darkGray)); mainSplitPane.setRightComponent(propertySheetPanel); vsSelectPanel.setBorder( BorderFactory.createTitledBorder( null, "Current Visual Style", TitledBorder.DEFAULT_JUSTIFICATION, TitledBorder.DEFAULT_POSITION, new Font("SansSerif", 1, 12), Color.darkGray)); optionButton.setToolTipText("Options..."); optionButton.setIcon(iconMgr.getIcon("optionIcon")); optionButton.setMargin(new Insets(2, 2, 2, 2)); optionButton.setComponentPopupMenu(menuMgr.getMainMenu()); GroupLayout vsSelectPanelLayout = new GroupLayout(vsSelectPanel); vsSelectPanel.setLayout(vsSelectPanelLayout); vsSelectPanelLayout.setHorizontalGroup( vsSelectPanelLayout .createParallelGroup(GroupLayout.Alignment.LEADING) .addGroup( vsSelectPanelLayout .createSequentialGroup() .addContainerGap() .addComponent(visualStyleComboBox, 0, 146, Short.MAX_VALUE) .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) .addComponent( optionButton, GroupLayout.PREFERRED_SIZE, 64, GroupLayout.PREFERRED_SIZE) .addContainerGap())); vsSelectPanelLayout.setVerticalGroup( vsSelectPanelLayout .createParallelGroup(GroupLayout.Alignment.LEADING) .addGroup( vsSelectPanelLayout .createSequentialGroup() .addGroup( vsSelectPanelLayout .createParallelGroup(GroupLayout.Alignment.BASELINE) .addComponent( visualStyleComboBox, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) .addComponent(optionButton)) // .addContainerGap( // GroupLayout.DEFAULT_SIZE, // Short.MAX_VALUE) )); GroupLayout layout = new GroupLayout(this); this.setLayout(layout); layout.setHorizontalGroup( layout .createParallelGroup(GroupLayout.Alignment.LEADING) .addComponent( vsSelectPanel, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(mainSplitPane, GroupLayout.DEFAULT_SIZE, 280, Short.MAX_VALUE)); layout.setVerticalGroup( layout .createParallelGroup(GroupLayout.Alignment.LEADING) .addGroup( layout .createSequentialGroup() .addComponent( vsSelectPanel, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) .addComponent(mainSplitPane, GroupLayout.DEFAULT_SIZE, 510, Short.MAX_VALUE))); } // </editor-fold>