/* 3magic Coffee Table Tutorial 7 Tutorial7.java - In-cell Editing. © 1997-1999 3magic. All rights reserved worldwide. */ import java.awt.*; import java.applet.*; import java.util.*; import java.awt.event.*; import CoffeeTable.Grid.*; public class Tutorial7 extends Applet implements ActionListener { // Labels for columns. String colLabels[] = {"First", "Last", "Fruit", "Color", "Salary"}; // Sample data. String cellData[][] = { {"Ray", "Yoshi", "apple", "red", "$50,000"}, {"Neal", "Bajaj", "mango", "orange", "$60,000"}, {"Greg", "Finn", "kiwi", "green", "$90,000"}, {"Fred", "Mertz", "banana", "yellow", "$30,000"}, {"Ethyl", "Nertz", "blueberry", "blue", "$35,000"}, {"Lucy", "Ricardo", "cherry", "magneta", "$40,000"}, {"Ricky", "Arnaz", "coconut", "white", "$45,000"}, {"Jeremy", "King", "watermelon", "pink", "$15,000"}, {"Thumper", "Lapin", "grape", "purple", "$25,000"}, {"Seargent", "Argent", "blackberry", "black?", "$65,000"}}; // Our grid. GridPanel fGrid; // Rows and Columns; int fNumRows = 10; int fNumCols = 5; // Some Buttons. int fNumButtons = 3; Button fButton[] = new Button[fNumButtons]; String buttonLabels[] = { "Edit Cell 2, 2", "Commit Editing", "Undo Editing"}; // A label. Label fLabel; // sub-class a GridAdapter to handle events class MyGridAdapter extends GridAdapter { // handle selection changes by updating the buttons public void gridSelChanged(GridEvent e) { updateButtons(); } // handle cancel editing by updating the buttons public void gridCancelEdit(GridEvent e) { updateButtons(); } // handle commiting editing by updating the buttons public void gridCommitEdit(GridEvent e) { updateButtons(); } // handle start of editing by updating the buttons public void gridStartEdit(GridEvent e) { updateButtons(); } } /** * Initialize. */ public void init() { // Instantiate a new Grid Panel with 10 rows and 5 columns // and other defaults like cell selection, row and column headers, // row and column lines enabled and with scrollbars. fGrid = new EditGridPanel(fNumRows, fNumCols); // Be sure to set the preferred size if you are using it in a // layout that resizes based on preferred size. fGrid.setSize(400, 200); // Show the row headers. fGrid.setRowHeaderWidth(30); fGrid.setRowNumbers(true); // CONFIGURE EDITING ----------------------- // And do it all in one line of Java... fGrid.setGridAttributes(new GridAttributes(fGrid, new Font("Courier", Font.PLAIN, 12), null, null, 0, GridPanel.EDIT_TEXT), true); // CONFIGURE SORTING ------------------------------------------ // Enable sorting for all columns. fGrid.setSortEnable(true); // Set sort column color to a very light gray. fGrid.setSortColumnColor(new Color(0xEFEFEF)); // Add the grid into the applet panel add(fGrid); // add a gridListener to handle selection change events fGrid.addGridListener(new MyGridAdapter()); // Add some data for display. this.loadData(); // Add some control buttons. for (int i = 0; i