gt:         gridBagConstraints.insets = new java.awt.Insets(4, 4, 4, 4);
context: /* -*- tab-width: 4 -*-
   *
   * Electric(tm) VLSI Design System
   *
   * File: LayoutImage.java
   *
   * Copyright (c) 2009 Sun Microsystems and Static Free Software
   *
   * Electric(tm) is free software; you can redistribute it and/or modify
   * it under the terms of the GNU General Public License as published by
   * the Free Software Foundation; either version 3 of the License, or
   * (at your option) any later version.
   *
   * Electric(tm) is distributed in the hope that it will be useful,
   * but WITHOUT ANY WARRANTY; without even the implied warranty of
   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   * GNU General Public License for more details.
   *
   * You should have received a copy of the GNU General Public License
   * along with Electric(tm); see the file COPYING.  If not, write to
   * the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
   * Boston, Mass 02111-1307, USA.
   */
  package com.sun.electric.tool.user.dialogs;
  
  import com.sun.electric.database.hierarchy.Cell;
  import com.sun.electric.database.prototype.NodeProto;
  import com.sun.electric.database.text.TextUtils;
  import com.sun.electric.database.topology.NodeInst;
  import com.sun.electric.technology.PrimitiveNode;
  import com.sun.electric.technology.Technology;
  import com.sun.electric.tool.Job;
  import com.sun.electric.tool.JobException;
  import com.sun.electric.tool.io.FileType;
  import com.sun.electric.tool.user.User;
  import com.sun.electric.tool.user.ui.WindowFrame;
  
  import javax.imageio.stream.ImageInputStream;
  import javax.imageio.ImageIO;
  import javax.imageio.ImageReader;
  import javax.swing.*;
  import java.awt.Canvas;
  import java.awt.Frame;
  import java.awt.Image;
  import java.awt.MediaTracker;
  import java.awt.Toolkit;
  import java.awt.geom.Point2D;
  import java.awt.image.BufferedImage;
  import java.awt.image.DataBufferByte;
  import java.awt.image.Raster;
  import java.util.Iterator;
  import java.io.File;
  
  /**
   * Class to handle the "Layout Image" dialog.  There is still a ton of
   * overlap left in here from LayoutText.java; at some point I will
   * either merge the two or else remove that overlap.  In particular,
   * LayoutText could benefit from "backporting" the new support for
   * grayscale images (which would give us antialiased layout text!)
   *
   * @author Adam Megacz <adam.megacz@sun.com>, derived from LayoutText.java
   */
  public class LayoutImage extends EDialog {
  
      /** Creates new form LayoutImage */
      public LayoutImage(Frame parent) {
          super(parent, true);
          initComponents();
  
          // make all text fields select-all when entered
          EDialog.makeTextFieldSelectAllOnTab(largestDotWidth);
          EDialog.makeTextFieldSelectAllOnTab(smallestDotWidth);
          EDialog.makeTextFieldSelectAllOnTab(minimumGutter);
          EDialog.makeTextFieldSelectAllOnTab(fileName);
  
          largestDotWidth.setText("32");
          smallestDotWidth.setText("22");
          minimumGutter.setText("16");
  //        fileName.setText("/Users/megacz/proj/fleet/marina/logo/marina-logo.png");
          monochrome.setSelected(false);
          reverseVideo.setSelected(false);
  
          Technology tech = Technology.getCurrent();
          for(Iterator<PrimitiveNode> it = tech.getNodes(); it.hasNext(); )
          {
              PrimitiveNode np = it.next();
              if (np.getFunction() == PrimitiveNode.Function.NODE)
                  textLayer.addItem(np.getName());
          }
  
          finishInitialization();
      }
  
      /** This method is called from within the constructor to
       * initialize the form.
       * WARNING: Do NOT modify this code. The content of this method is
       * always regenerated by the Form Editor.
       */
      @SuppressWarnings("unchecked")
      // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
      private void initComponents() {
          java.awt.GridBagConstraints gridBagConstraints;
  
          cancel = new javax.swing.JButton();
          ok = new javax.swing.JButton();
          jLabel1 = new javax.swing.JLabel();
          smallestDotWidth = new javax.swing.JTextField();
          jLabel2 = new javax.swing.JLabel();
          largestDotWidth = new javax.swing.JTextField();
          jLabel3 = new javax.swing.JLabel();
          minimumGutter = new javax.swing.JTextField();
          jLabel5 = new javax.swing.JLabel();
          textLayer = new javax.swing.JComboBox();
          reverseVideo = new javax.swing.JCheckBox();
          monochrome = new javax.swing.JCheckBox();
          fileName = new javax.swing.JTextField();
          jLabel4 = new javax.swing.JLabel();
          openFileButton = new javax.swing.JButton();
  
          setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
          setTitle("Layout Image");
          getContentPane().setLayout(new java.awt.GridBagLayout());
  
          cancel.setText("Cancel");
          cancel.addActionListener(new java.awt.event.ActionListener() {
              public void actionPerformed(java.awt.event.ActionEvent evt) {
                  cancel(evt);
              }
          });
          gridBagConstraints = new java.awt.GridBagConstraints();
          gridBagConstraints.gridx = 0;
          gridBagConstraints.gridy = 9;
          gridBagConstraints.insets = new java.awt.Insets(4, 4, 4, 4);
          getContentPane().add(cancel, gridBagConstraints);
  
          ok.setText("OK");
          ok.addActionListener(new java.awt.event.ActionListener() {
              public void actionPerformed(java.awt.event.ActionEvent evt) {
                  ok(evt);
              }
          });
          gridBagConstraints = new java.awt.GridBagConstraints();
          gridBagConstraints.gridx = 1;
          gridBagConstraints.gridy = 9;
          gridBagConstraints.insets = new java.awt.Insets(4, 4, 4, 4);
          getContentPane().add(ok, gridBagConstraints);
  
          jLabel1.setText("Width of smallest dot:");
          gridBagConstraints = new java.awt.GridBagConstraints();
          gridBagConstraints.gridx = 0;
          gridBagConstraints.gridy = 2;
          gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
          gridBagConstraints.insets = new java.awt.Insets(4, 4, 4, 4);
          getContentPane().add(jLabel1, gridBagConstraints);
  
          smallestDotWidth.setColumns(8);
          smallestDotWidth.setText(" ");
          gridBagConstraints = new java.awt.GridBagConstraints();
          gridBagConstraints.gridx = 1;
          gridBagConstraints.gridy = 2;
          gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
          gridBagConstraints.insets = new java.awt.Insets(4, 4, 4, 4);
          getContentPane().add(smallestDotWidth, gridBagConstraints);
  
          jLabel2.setText("Width of largest dot:");
          gridBagConstraints = new java.awt.GridBagConstraints();
          gridBagConstraints.gridx = 0;
          gridBagConstraints.gridy = 3;
          gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
          gridBagConstraints.insets = new java.awt.Insets(4, 4, 4, 4);
          getContentPane().add(jLabel2, gridBagConstraints);
  
          largestDotWidth.setColumns(8);
          largestDotWidth.setText(" ");
          gridBagConstraints = new java.awt.GridBagConstraints();
          gridBagConstraints.gridx = 1;
          gridBagConstraints.gridy = 3;
          gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
          gridBagConstraints.insets = new java.awt.Insets(4, 4, 4, 4);
          getContentPane().add(largestDotWidth, gridBagConstraints);
  
          jLabel3.setText("Minimum gutter between dots:");
          gridBagConstraints = new java.awt.GridBagConstraints();
          gridBagConstraints.gridx = 0;
          gridBagConstraints.gridy = 4;
          gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
          gridBagConstraints.insets = new java.awt.Insets(4, 4, 4, 4);
          getContentPane().add(jLabel3, gridBagConstraints);
  
          minimumGutter.setColumns(8);
          minimumGutter.setText(" ");
          gridBagConstraints = new java.awt.GridBagConstraints();
          gridBagConstraints.gridx = 1;
          gridBagConstraints.gridy = 4;
          gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
          gridBagConstraints.insets = new java.awt.Insets(4, 4, 4, 4);
          getContentPane().add(minimumGutter, gridBagConstraints);
  
          jLabel5.setText("Layer:");
          gridBagConstraints = new java.awt.GridBagConstraints();
          gridBagConstraints.gridx = 0;
          gridBagConstraints.gridy = 6;
          gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
  