home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
BUG 15
/
BUGCD1998_06.ISO
/
aplic
/
jbuilder
/
jsamples.z
/
AttributePanel.java
< prev
next >
Wrap
Text File
|
1997-07-03
|
5KB
|
162 lines
package borland.samples.jbcl.treecontrol;
import java.awt.*;
import java.awt.event.*;
import borland.jbcl.layout.*;
import borland.jbcl.control.*;
import borland.jbcl.model.*;
import borland.jbcl.view.*;
import borland.jbcl.util.*;
/**
* A BevelPanel based attribute panel class. This produces a generic attribute
* page for displaying attributes/properties and their associated values
*
* @version 1.0, 06/10/97
* @author Borland Development Team
*/
public class AttributePanel extends BevelPanel {
GridLayout gridLayout1 = new GridLayout();
GridControl gridControl1 = new GridControl();
BasicMatrixContainer bmc = new BasicMatrixContainer(0, 2);
ColumnView[] tempColumns = new ColumnView[2];
/**
* Constructor the attribute panel and it's UI elements
*/
public AttributePanel() {
try {
jbInit();
}
catch (Exception e) {
e.printStackTrace();
}
}
/**
* UI elements of the attribute panel
*/
public void jbInit() throws Exception{
this.setBevelInner(BevelPanel.FLAT);
tempColumns[0] = new ColumnView();
tempColumns[0].setAlignment(Alignment.LEFT | Alignment.MIDDLE);
tempColumns[0].setCaption("Attribute");
tempColumns[0].setWidth(100);
tempColumns[1] = new ColumnView();
tempColumns[1].setAlignment(Alignment.LEFT | Alignment.MIDDLE);
tempColumns[1].setCaption("Value");
tempColumns[1].setWidth(305);
gridControl1.setColumnViews(tempColumns);
gridControl1.setDragSubfocus(false);
gridControl1.setEditInPlace(false);
gridControl1.setGridVisible(false);
gridControl1.setResizableRows(false);
gridControl1.setRowHeaderVisible(false);
gridControl1.setSelectRow(true);
gridControl1.setShowFocus(false);
gridControl1.setModel(bmc);
gridControl1.setViewManager(new BasicViewManager(new TextItemPainter(), new TextItemEditor()));
this.setLayout(gridLayout1);
this.add(gridControl1, null);
}
/**
* Add an item name and string value
* @param name The name of the item to insert
* @param value The initial string value to set the item to
*/
public void addItem(String name, String value) {
// Insert a new row into the container
bmc.addRow();
// Add the item at the end
bmc.set(bmc.getRowCount()-2, 0, name);
bmc.set(bmc.getRowCount()-2, 1, value);
}
/**
* Add an item name and boolean value
* @param name The name of the item to insert
* @param state The initial boolean value to set the item to
*/
public void addItem(String name, boolean state) {
this.addItem(name, (state ? "True" : "False"));
}
/**
* Loop through the container. This will remove all occurances
* of the item just in case there are duplicates. Use
* removeItem(int) to remove only a specific item.
* @param name The string representation of the item to remove
*/
public void removeItem(String name) {
for (int i=0;i<bmc.getRowCount();i++) {
if (bmc.get(i, 0).equals(name) == true)
bmc.removeRow(i);
}
}
/**
* This will remove only the item specified in the index paramater
* @param index The index of the item to remove (base 1)
*/
public void removeItem(int index) {
bmc.removeRow(index);
}
/**
* This will set only the item specified in the index paramater
* @param index The index of the item to set (base 1)
* @param state The boolean value to set the specified item to
*/
public void setValue(int index, boolean state) {
String value;
this.setValue(index, (state ? "True" : "False"));
}
/**
* This will set only the item specified in the index paramater
* @param index The index of the item to set (base 1)
* @param value The string value to set the specified item to
*/
public void setValue(int index, String value) {
bmc.set(index, 1, value);
}
/**
* Loop through the container. This will set all occurances
* of the item just in case there are duplicates. Use
* setItem(int) to set only a specific item. If the specified
* item does not exist, it is added to the display.
* @param name The string representation of the item to modify
* @param state The boolean value to set the specified item to
*/
public void setValue(String name, boolean state) {
this.setValue(name, (state ? "True" : "False"));
}
/**
* Loop through the container. This will set all occurances
* of the item just in case there are duplicates. Use
* setItem(int) to set only a specific item. If the specified
* item does not exist, it is added to the display.
* @param name The string representation of the item to modify
* @param value The string value to set the specified item to
*/
public void setValue(String name, String value) {
boolean foundItem = false;
if (bmc.getRowCount() > 1) {
for (int i=0;i<bmc.getRowCount()-1;i++) {
if (bmc.get(i, 0).equals(name) == true) {
foundItem = true;
bmc.set(i, 1, value);
}
}
}
if (foundItem == false)
this.addItem(name, value);
}
}