Brought to you by EarthWeb
ITKnowledge Logo Login Graphic Y2K crisis team
Y2K crisis team
ITKnowledge
Search this book:
 
Search the site:
 
EXPERT SEARCH ----- nav

EarthWeb Direct

EarthWeb Direct

EarthWeb sites: other sites

Previous Table of Contents Next


MapInfo.java

MapInfo.java class extracts the x,y coordinates from the flight’s string for a particular graphic map. Listing 10-13 shows its source code.

Listing 10-13: MapInfo.java.

//
// MapInfo.java - informations regarding airport's position on a map
//
// Copyright (C) 1996 by Connect Software. All rights reserved.
//
// Written by Gionata Mettifogo, Peter Ham.
//
package airplet; // airplet's package
import java.util.*; // utility classes
/** Information about an airport's position on a map. */
class MapInfo
{
  /** Initialize from a 'map(x,y)' string. */
  MapInfo(String map)
  {
      StringTokenizer sTokenizer = new StringTokenizer(map,"(,)"); // name is encoded
        as name(x,y) so use ( and comma as separators
      name = sTokenizer.nextToken().toLowerCase(); // name of this map (eg. 'usa',
        'europe', 'world')
      x = Integer.parseInt(sTokenizer.nextToken()); // coordinate of the airport in this
        map
      y = Integer.parseInt(sTokenizer.nextToken());
  }
  String name; // name of the map
  int x,y; // coordinates of the airport on this map
  MapInfo next = null; // next map (this is a linked list)
  void append(MapInfo item)
  {
      if(next != null) next.append(item); else next = item; // appends item at the end of
        the linked list
  }
  public String toString()
  {
      return "MapInfo[" + name + "," + x + "," + y + "]"; // returns MapInfo[name,x,y]
  }
}

MultilineLabel.java

MultilineLabel.java is simply a label that can display multiple lines of text. It also provides text shadow for the drawn string. Listing 10-14 shows the source code for this class.

Listing 10-14: MultilineLabel.java.

//
// MultilineLabel.java - a label that can draw several lines of text
//
// Copyright (C) 1996 by Connect Software. All rights reserved.
//
// Written by Gionata Mettifogo, Peter Ham.
//
package airplet;
import java.awt.*;
import java.util.*;
public class MultilineLabel extends java.awt.Canvas
{
  public MultilineLabel(int alignment)
  {
      align = alignment;
  }
  private String text; private int align; // text and alignment (see constants in Label)
  public void setText(String text)
  {
      this.text = text;
  }
  /** Draw the multiline label aligned as specified during object's construction. */
  public void paint(Graphics iGraphics)
  {
      FontMetrics fm = iGraphics.getFontMetrics(); // get information on the font's sizes
      StringTokenizer tokens = new StringTokenizer(text,"\n"); // separate different lines
      int w = size().width, h = fm.getHeight(); // line height and label's width
      for(int y = h ; tokens.hasMoreTokens() ; y += h) // scan all lines in the label
      {
           String line = tokens.nextToken(); // retrieve line
           int x = 0;
           if(align == Label.CENTER || align == Label.RIGHT) // if line is centered
             or right aligned
           {
                    x = w - fm.stringWidth(line); if(align == Label.CENTER) x /= 2;
                // calculate spacing on left side
           }
           shadowString(iGraphics,line,x,y); // draw the line
      }
  }
  public Dimension preferredSize()
  {
      FontMetrics fm = getGraphics().getFontMetrics(); // get information on the font's
        sizes
      StringTokenizer tokens = new StringTokenizer(text,"\n"); // separate different lines
      Dimension dimension = new Dimension(0,fm.getHeight() * tokens.countTokens() +
        fm.getMaxDescent() + 1);
      while(tokens.hasMoreTokens()) // scan lines
      {
           String line = tokens.nextToken(); // retrieve line
           dimension.width = Math.max(fm.stringWidth(line),dimension.width); //
             width is the length of the longest line
      }
      return dimension;
  }
  /**
  * Draws the given string at the given position using a
  * subtle 1 pixel gray shadow. Light comes from the upper
  * left corner (where the Apple used to be).
  */
  public void shadowString(Graphics iGraphics,String iString,int x,int y)
  {
      Color color = iGraphics.getColor();
      iGraphics.setColor(Color.lightGray);
      iGraphics.drawString(iString,x+1,y+1);
      iGraphics.setColor(color);
      iGraphics.drawString(iString,x,y);
  }
}

Handling Multimedia Content

SQL does not provide mechanisms that are powerful enough to handle binary large objects, known as BLOBs. Fortunately, JDBC contains the necessary methods to insert and extract BLOBs.

Sending BLOBS

The next example is a simple command line tool used to insert binary large objects in a table. Any kind of BLOB may be used, including pictures, audio files, binary data, and texts. It is quite simple to use. The tool prompts you for a database URL, a log in, a password, the name of the table to be updated, the BLOB column name, which is the column that holds a BLOB, and the BLOB file name.

A row must exist in the table before trying to insert a BLOB. For example, a table of employees must contain a row for Jones before a picture can be inserted for this employee. To locate this row, the program also prompts for a column name and value, which represent a search criteria. In the case of employee Jones, simply use “name” as column name and “Jones” as column value.

All parameters but the database URL, log in, and password may be passed on the command line. In this case, the program will use the default URL, log in, and password. This method is extremely convenient for inserting multiple BLOBs at once from a shell script.

Batch Command

Consider this script.

java txblob -c employees pict name Jones /tmp/pictures/jones.jpg
java txblob -c employees pict name Dupont /tmp/pictures/dupont.jpg
java txblob -c employees pict name Duke /tmp/pictures/duke.jpg
java txblob -c employees pict name Jack /tmp/pictures/jack.jpg
...
...

It inserts the pictures of Jones, Dupont, Duke, and Jack in the table of employees.


Previous Table of Contents Next
HomeAbout UsSearchSubscribeAdvertising InfoContact UsFAQs
Use of this site is subject to certain Terms & Conditions.
Copyright (c) 1996-1999 EarthWeb Inc. All rights reserved. Reproduction in whole or in part in any form or medium without express written permission of EarthWeb is prohibited. Read EarthWeb's privacy statement.