next up previous contents
Next: GraphAlgorithm Class Up: GraphStuff Package Previous: Vertex Class

General Class

The General class includes methods to access data which is relevant to more than one of the various GraphStuff package classes. For example, both Edge and Vertex objects require a Font object for drawing. Also note that Edge, Vertex, and GraphControlPanel objects all require knowledge of what Color objects are available. The General class provides methods to access and modify the outer radius of Vertex objects (vor), because the width of Edge objects depends directly on the vor. Finally, the General class includes variables which the GraphControlPanel sets to indicate to Vertex and Edge objects whether labels, demands, weights, flows, capacities, and minima should be displayed.

package GraphStuff;

import java.awt.*;
import java.util.*;

class General extends Object {

   static final int minFont = 8;

   static final int maxFont = 28;

   private static Font p_f, p_fA[];

   static { 
       p_fA = new Font[maxFont-minFont+1];
       for(int i=0;i<p_fA.length;i++) 
       p_fA[i] = new Font("Courier", Font.PLAIN, i+minFont);
       fontSize(20);
   }

   static void fontSize(int size) {
      p_f = p_fA[size-minFont];
   }

   static int fontSize() { return p_f.getSize(); };

   static Font f() {return p_f ;};

   static final int defaultColorNum=0;

   static final int defaultWeight=1;

   static final int defaultFlow=0;

   static final int defaultCapacity=999;

   static final int defaultMinimum=0;

   static final int defaultDemand=0;

   static final String alphas = 
   "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";

   static final Color highlightColor = Color.yellow;

   static final Color gridColor= new Color(128,128,128);

   static final Color gridBright= new Color (200, 200, 200);

   static final Color gridDark= new Color (100,100,100);

   static final Color textColor = Color.black;

   static boolean showLabels=false,
                  showWeights=false,
                  showCapacities=false,
                  showMinimums=false,
                  showFlows=false,
                  showDemands=false;

   private static final Color[] p_colors={
                  Color.red,
                  Color.green,
                  Color.blue,
                  Color.yellow,
                  Color.magenta,
                  Color.cyan,
                  Color.orange,
                  Color.pink,
                  Color.green.darker(),
                  Color.blue.darker(),
                  Color.yellow.darker(),
                  Color.magenta.darker(),
                  Color.cyan.darker(),
                  Color.pink.darker(),
                  Color.green.brighter(),
                  Color.blue.brighter(),
                  Color.yellow.brighter(),
                  Color.magenta.brighter(),
                  Color.cyan.brighter(),
                  Color.black
                 };

   static final int maxColor = p_colors.length;

   static Color colors(int num) {
      if(num<=0)
        return p_colors[0];
      else if(num>=p_colors.length)
        return p_colors[p_colors.length-1];
      else return p_colors[num];
   }

   static int p_vor, p_vir;

   static int[] halfBarWidths=new int[5]; 

   static Color[] barColors=new Color[4];

   static int barsInUse;

   static {
      barColors[0] = highlightColor;
      barColors[1] = gridDark;
      barColors[2] = gridColor;
      barColors[3] = gridDark;
      vor(14);
   }

   static void vor(int or) {
      if (p_vor == or)
        return;
      p_vor=or;
      p_vir=p_vor/2;
      if (p_vor>14) {
         barsInUse=5;
         halfBarWidths[0]=p_vor/2;
         halfBarWidths[1]=p_vor/2-2;
         halfBarWidths[2]=p_vor/2-3;
         halfBarWidths[3]=p_vir/2;
         halfBarWidths[4]=p_vir/2-1;
      }
      else if (p_vor > 12 ){
         barsInUse=2;
         halfBarWidths[0]=p_vor/2-2;
         halfBarWidths[1]=p_vor/2-4;
      } else {
         barsInUse=2;
         halfBarWidths[0]=4;
         halfBarWidths[1]=2;
      }
   }

   static final int vor() {
     return p_vor;
   }

   static final int vir() {
     return p_vir;
   }

}



Kelly Waters
Mon Oct 27 18:18:15 EST 1997