/*******************************************************************************
* Copyright 2007 Neptuny s.r.l. - www.neptuny.com
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*******************************************************************************/
package com.neptuny.xgrapher.cli;
import java.awt.Dimension;
import javax.swing.JPanel;
import com.l2fprod.common.demo.BeanBinder;
import com.l2fprod.common.propertysheet.PropertySheet;
import com.l2fprod.common.propertysheet.PropertySheetPanel;
import com.l2fprod.common.swing.LookAndFeelTweaks;
import com.neptuny.xgrapher.cli.controller.Application;
import com.neptuny.xgrapher.cli.controller.XGrapherEvent;
import com.neptuny.xgrapher.cli.controller.XGrapherEventListener;
import com.neptuny.xgrapher.cli.controller.XGrapherEventType;
/**
* This component is responsible for showing the properties and details of the currently selected
* graph element.
*
* @author Riccardo Govoni [riccardo.govoni@neptuny.it]
* @since Sep 25, 2007
*
*/
public class XGrapherPropertySheet extends JPanel {
/* the application model */
private Application app;
/* the binder which updates the property sheet */
private BeanBinder binder = null;
PropertySheetPanel sheet = null;
/* the listener which receives events from the commbus */
private XGrapherEventListener listener = new XGrapherEventListener() {
@Override
public void eventOccurred(XGrapherEvent evt) {
showProperties(evt.getNewValue());
}
};
public XGrapherPropertySheet(Application app) {
this.app = app ;
setLayout(LookAndFeelTweaks.createVerticalPercentLayout());
app.commBus().addEventListener(XGrapherEventType.EDGE_SELECTION, listener);
app.commBus().addEventListener(XGrapherEventType.NODE_SELECTION, listener);
setPreferredSize(new Dimension(200,200));
}
private void init() {
if (sheet!=null) {
remove(sheet);
sheet=null;
}
sheet=new PropertySheetPanel();
sheet.setMode(PropertySheet.VIEW_AS_CATEGORIES);
sheet.setDescriptionVisible(true);
sheet.setSortingCategories(true);
sheet.setSortingProperties(true);
sheet.setRestoreToggleStates(true);
add(sheet, "*");
}
/**
* Updates the property sheet.
*
* @param obj the object whose properties will be shown on the property sheet.
*/
private void showProperties(Object obj) {
if (obj==null) {
this.setVisible(false);
return;
}
this.setVisible(true);
init();
if (binder!=null) {
binder.unbind();
binder=null;
}
// everytime a property change, update the sheet with it
binder=new BeanBinder(obj,sheet);
// refresh
sheet.updateUI();
}
}