home *** CD-ROM | disk | FTP | other *** search
- Save Format v2.0(1)
- @begin Form "Sortable_Vector_Form"
- Exported 0;
- Abstract 0;
- Interface 0;
- PackageName "";
-
- @begin Object "powersoft.jcm.ui.Form"
- Font "Dialog-Plain-8";
- ControlScope "Private";
- BackColor "Color.lightGray";
- ForeColor "Color.black";
- Text "Sortable Vector";
- Visible "1";
- DataSource "NULL";
- DataColumns "";
- BoundControl "0";
- @begin Event "powersoft.jcm.event.Create"
- GencodeSrcLine 169;
- FunctionName "Sortable_Vector_Form_Create";
- @end;
- @begin UserFunction "Form1()"
- Compiler 1;
- GencodeSrcLine 114;
- FunctionName "Sortable_Vector_Form::Form1()";
- @end;
- @begin UserFunction "updateListbox()"
- GencodeSrcLine 153;
- FunctionName "Sortable_Vector_Form::updateListbox()";
- @end;
- @begin UserFunction "Prototype for updateListbox()"
- Private 1;
- GencodeSrcLine -1;
- FunctionName "Sortable_Vector_Form::Prototype for updateListbox()";
- @end;
- @begin UserFunction "loadVector()"
- GencodeSrcLine 125;
- FunctionName "Sortable_Vector_Form::loadVector()";
- @end;
- @begin UserFunction "Prototype for loadVector()"
- Private 1;
- GencodeSrcLine -1;
- FunctionName "Sortable_Vector_Form::Prototype for loadVector()";
- @end;
- @begin UserFunction "sequentialSearch(String inName)"
- GencodeSrcLine 134;
- FunctionName "Sortable_Vector_Form::sequentialSearch(String inName)";
- @end;
- @begin UserFunction "Prototype for sequentialSearch(String inName)"
- Private 1;
- GencodeSrcLine -1;
- FunctionName "Sortable_Vector_Form::Prototype for sequentialSearch(String inName)";
- @end;
- ResID 103;
- DesignName Sortable_Vector_Form;
- TabIndex 0;
- DesignRect 130,135,298,232;
- @end;
-
- @begin Menu
- DesignName "menu_1";
- IsDefault 1;
- DesignRect 250,165,19,17;
- @begin Popup
- Name "Sort";
- Caption "&Sort";
- @begin Item
- Name "AlphaSort";
- Caption "&Alpha Sort";
- @begin Event "powersoft.jcm.event.Click"
- GencodeSrcLine 200;
- FunctionName "menu_1_AlphaSort_Click";
- @end;
- @end;
- @begin Item
- Name "NameLengthSort";
- Caption "&Name Length Sort";
- @begin Event "powersoft.jcm.event.Click"
- GencodeSrcLine 231;
- FunctionName "menu_1_NameLengthSort_Click";
- @end;
- @end;
- @begin Item
- Name "Scramble";
- Caption "&Scramble";
- @begin Event "powersoft.jcm.event.Click"
- GencodeSrcLine 275;
- FunctionName "menu_1_Scramble_Click";
- @end;
- @end;
- @end;
- @begin Popup
- Name "Name";
- Caption "&Name";
- @begin Item
- Name "AddWaldo";
- Caption "&Add Waldo";
- @begin Event "powersoft.jcm.event.Click"
- GencodeSrcLine 188;
- FunctionName "menu_1_AddWaldo_Click";
- @end;
- @end;
- @begin Item
- Name "RemoveWaldo";
- Caption "&Remove Waldo";
- @begin Event "powersoft.jcm.event.Click"
- GencodeSrcLine 255;
- FunctionName "menu_1_RemoveWaldo_Click";
- @end;
- @end;
- @begin Item
- Name "FindWaldo";
- Caption "&Find Waldo";
- @begin Event "powersoft.jcm.event.Click"
- GencodeSrcLine 213;
- FunctionName "menu_1_FindWaldo_Click";
- @end;
- @end;
- @begin Item
- Name "RemoveThirdName";
- Caption "&Remove Third Name";
- @begin Event "powersoft.jcm.event.Click"
- GencodeSrcLine 243;
- FunctionName "menu_1_RemoveThirdName_Click";
- @end;
- @end;
- @end;
- @end;
-
- @begin Object "powersoft.jcm.ui.ListBox"
- Font "<Inherited>";
- Sort "0";
- DataTrackRow "0";
- DataBindAsLookup "0";
- DataLookupSource "NULL";
- DataLookupColumns "";
- BackColor "Color.lightGray";
- ForeColor "Color.black";
- ResizePercentages "[ 0 0 50 100 ]";
- Text "";
- Visible "1";
- DataSource "NULL";
- DataColumns "";
- BoundControl "0";
- ResID 100;
- DesignName lb_1;
- TabIndex 1;
- DesignRect 0,5,140,175;
- @begin ComponentData "lb_1"
- @end;
- @end;
-
- @begin Object "powersoft.jcm.ui.Label"
- Font "<Inherited>";
- BackColor "Color.lightGray";
- ForeColor "Color.black";
- ResizePercentages "[ 0 100 0 0 ]";
- Text "";
- Visible "1";
- DataSource "NULL";
- DataColumns "";
- BoundControl "0";
- ResID 109;
- DesignName label_messages;
- TabIndex 2;
- DesignRect 0,185,290,15;
- @end;
-
- @begin Object "powersoft.jcm.ui.TextBox"
- WTextBoxMultiLine 1;
- WTextBoxReadOnly 1;
- Font "<Inherited>";
- PasswordCharacter "0";
- BackColor "Color.white";
- ForeColor "Color.black";
- ResizePercentages "[ 50 0 50 100 ]";
- Text "";
- Visible "1";
- DataSource "NULL";
- DataColumns "";
- BoundControl "0";
- ResID 101;
- DesignName textb_info;
- TabIndex 3;
- DesignRect 145,5,145,175;
- @end;
-
- @begin HPPPrefixBlock
- @begin-code HPPPrefix
-
- // add your custom import statements here
- import java.util.Enumeration;
- import powersoft.jcm.util.*;
-
- @end-code;
- GencodeSrcLine 15;
- @end;
-
- @begin CPPPrefixBlock
- @begin-code CPPPrefix
-
-
- @end-code;
- GencodeSrcLine 15;
- @end;
-
- @begin ClassContentsBlock
- @begin-code ClassContents
-
- // add your data members here
- SortableVector _nameVector = new SortableVector();
- String _sortType = new String("none");
- final int ELEMENTS = 29;
- String[] _nameList =
- {
- "John",
- "Brad",
- "Jim",
- "Greg",
- "Dan",
- "Dave",
- "Wesley",
- "Eric",
- "Chris",
- "Geno",
- "Rob",
- "David",
- "Ivan",
- "Waldo",
- "Mark",
- "Kevin",
- "Paul",
- "Bill",
- "Eugene",
- "Tim",
- "Asif",
- "Michael",
- "Thorsten",
- "Graham",
- "Jim",
- "Jack",
- "Lisa",
- "Anthony",
- "Brian",
- };
-
- @end-code;
- GencodeSrcLine 305;
- @end;
-
- @begin-code BaseClassList
-
- extends powersoft.jcm.ui.Form
-
- @end-code;
-
- @begin-code GeneratedClassContents
-
- VectorSample();
-
- @end-code;
-
- @begin-code Code "Sortable_Vector_Form::Form1()"
-
- //****************************
- /**
- * This class displays the form and components. It also
- * handles the user generated events.
- */
- public @CLASSNAME@()
- //****************************
- {
- super();
- }
-
- @end-code;
-
- @begin-code Code "Sortable_Vector_Form::updateListbox()"
-
- public void updateListbox()
- //****************************
- {
- Enumeration e;
-
- lb_1.deleteAll();
-
- e = _nameVector.getElements();
-
- while (e.hasMoreElements () )
- {
- String currentElement = (String) e.nextElement();
- lb_1.add(currentElement);
- }
- }
-
- @end-code;
-
- @begin-code Code "Sortable_Vector_Form::Prototype for updateListbox()"
-
- public:
- void updateListbox();
-
- @end-code;
-
- @begin-code Code "Sortable_Vector_Form::loadVector()"
-
- public void loadVector()
- //****************************
- {
- _nameVector.clear();
- for (int t = 0; t<ELEMENTS; t++)
- _nameVector.append(_nameList[t]);
-
- }
-
- @end-code;
-
- @begin-code Code "Sortable_Vector_Form::Prototype for loadVector()"
-
- public:
- void loadVector();
-
- @end-code;
-
- @begin-code Code "Sortable_Vector_Form::sequentialSearch(String inName)"
-
- public int sequentialSearch(String inName)
- //****************************
- {
- Enumeration e;
- int count = 0;
- e = _nameVector.getElements();
-
- while (e.hasMoreElements() )
- {
- String currentElement = (String) e.nextElement();
- if (currentElement.equals(inName))
- {
- return count;
- }
- count++;
- }
- return -1;
- }
-
- @end-code;
-
- @begin-code Code "Sortable_Vector_Form::Prototype for sequentialSearch(String inName)"
-
- public:
- int sequentialSearch(String inName);
-
- @end-code;
-
- @begin-code Code "Sortable_Vector_Form_Create"
-
- public boolean Sortable_Vector_Form_Create(powersoft.jcm.event.CreateEvent event)
- //****************************
- {
- loadVector();
- updateListbox();
- String info = "This example demonstrates the use\n" +
- "of the SortableVector class. The list\n" +
- "of names displayed in the listbox is\n" +
- "sorted in a SortableVector called\n" +
- "_nameVector. The various menu items\n" +
- "perform operations on this vector and\n" +
- "update the listbox to visually display\n" +
- "the results of the operation. The\n" +
- "relevant code can be found in the menu\n" +
- "item click event handlers.";
- textb_info.setText(info);
- return false;
- }
-
- @end-code;
-
- @begin-code Code "menu_1_AlphaSort_Click"
-
- public boolean menu_1_AlphaSort_Click(powersoft.jcm.event.ClickEvent event)
- //****************************
- {
- CompareRoutine routine = StringUtility.getCompareRoutine( false );
- _nameVector.setCompareRoutine( routine );
-
- _sortType = "alpha";
- _nameVector.sort();
- updateListbox();
-
- return false;
- }
-
- @end-code;
-
- @begin-code Code "menu_1_NameLengthSort_Click"
-
- public boolean menu_1_NameLengthSort_Click(powersoft.jcm.event.ClickEvent event)
- //****************************
- {
- _nameVector.setCompareRoutine( new StringLengthSort() );
-
- _sortType = "namelength";
- _nameVector.sort();
- updateListbox();
-
- return false;
- }
-
- @end-code;
-
- @begin-code Code "menu_1_Scramble_Click"
-
- public boolean menu_1_Scramble_Click(powersoft.jcm.event.ClickEvent event)
- //****************************
- {
- _nameVector = new SortableVector();
- loadVector();
- updateListbox();
- _sortType = "none";
-
- return false;
- }
-
- @end-code;
-
- @begin-code Code "menu_1_AddWaldo_Click"
-
- public boolean menu_1_AddWaldo_Click(powersoft.jcm.event.ClickEvent event)
- //****************************
- {
- if (_sortType.equals("none"))
- _nameVector.insert((int)(Math.random()*_nameVector.getCount()), "Waldo");
- else
- _nameVector.insert("Waldo");
- updateListbox();
-
- return false;
- }
-
- @end-code;
-
- @begin-code Code "menu_1_RemoveWaldo_Click"
-
- public boolean menu_1_RemoveWaldo_Click(powersoft.jcm.event.ClickEvent event)
- //****************************
- {
- int position = -1;
-
- if (!_sortType.equals("alpha"))
- position = sequentialSearch("Waldo");
- else
- position = _nameVector.binarySearch("Waldo");
-
- if (position > -1)
- {
- _nameVector.removeAt(position);
- updateListbox();
- }
-
-
- return false;
- }
-
- @end-code;
-
- @begin-code Code "menu_1_FindWaldo_Click"
-
- public boolean menu_1_FindWaldo_Click(powersoft.jcm.event.ClickEvent event)
- //****************************
- {
- int position = 0;
-
- if (!_sortType.equals("alpha"))
- position = sequentialSearch("Waldo") + 1;
- else
- position = (_nameVector.binarySearch("Waldo") + 1);
-
- if (position != 0)
- label_messages.setText("Waldo found at position " + position + ".");
- else
- label_messages.setText("Waldo not found.");
-
- return false;
- }
-
- @end-code;
-
- @begin-code Code "menu_1_RemoveThirdName_Click"
-
- public boolean menu_1_RemoveThirdName_Click(powersoft.jcm.event.ClickEvent event)
- //****************************
- {
- if (_nameVector.getCount() > 2)
- {
- _nameVector.removeAt(2);
- updateListbox();
- }
-
- return false;
- }
-
- @end-code;
- @end;
-