import java.awt.*; import java.awt.event.*; import SimpleOutput; import Comparator; /** *Provides the html tags which can be added to an html email * *author Flamingo */ public class EditHTML extends Frame implements WindowListener { // -------------------------------- // Fields // -------------------------------- private Label colorLabel = null; private Label fontLabel = null; private Label styleLabel = null; private Checkbox color1 = null; private Checkbox color2 = null; private Checkbox color3 = null; private Checkbox color4 = null; private Checkbox color5 = null; private Checkbox color6 = null; private Checkbox styleItalics = null; private Checkbox styleBold = null; private Checkbox styleTeletype = null; private Checkbox font1 = null; private Checkbox font2 = null; private Checkbox font3 = null; private CheckboxGroup checkGroup1 = new CheckboxGroup(); private CheckboxGroup checkGroup2 = new CheckboxGroup(); private Button ReturnTags; private String colortag = ""; private String colortag2 = ""; private String fonttag = ""; private String fonttag2 = ""; protected String textSelection = ""; protected String boldtag = ""; protected String boldtag2 = ""; protected String italicstag = ""; protected String italicstag2 = ""; protected String teletypetag = ""; protected String teletypetag2 = ""; protected String colorselected = ""; protected Frame frame; // ----------------------------- // Constructors // ----------------------------- public EditHTML(String selection) { // Call super constructor. super( "Designer Gmail" ); textSelection = selection; // Set up container component setBackground( new Color( 0, 255, 30 ) ); setForeground( new Color( 50, 50, 255 ) ); setSize( new Dimension( 150, 300 ) ); setResizable( true ); //Add listeners. addWindowListener( this ); // Make the GUI. makeGUI(); } // --------------------------- // GUI builder // --------------------------- private void makeGUI() { // Create the GUI system. GridBagLayout mainLayout = new GridBagLayout(); setLayout( mainLayout ); colorLabel = new Label( "Color", Label.CENTER ); mainLayout.setConstraints( colorLabel, makeGridCons( 0, 6, 4, 2, 100, 100, GridBagConstraints.BOTH, GridBagConstraints.CENTER, 0, 0, 0, 0, 0, 0 ) ); add( colorLabel ); colorLabel.setBackground( new Color( 192, 192, 192 ) ); colorLabel.setForeground( new Color( 0, 0, 0 ) ); colorLabel.setEnabled( true ); colorLabel.setVisible( true ); fontLabel = new Label( "Font", Label.CENTER ); mainLayout.setConstraints( fontLabel, makeGridCons( 5, 6, 4, 2, 100, 100, GridBagConstraints.BOTH, GridBagConstraints.CENTER, 0, 0, 0, 0, 0, 0 ) ); add( fontLabel ); fontLabel.setBackground( new Color( 192, 192, 192 ) ); fontLabel.setForeground( new Color( 0, 0, 0 ) ); fontLabel.setEnabled( true ); fontLabel.setVisible( true ); styleLabel = new Label( "Style", Label.CENTER ); mainLayout.setConstraints( styleLabel, makeGridCons( 0, 0, 9, 2, 100, 100, GridBagConstraints.BOTH, GridBagConstraints.CENTER, 0, 0, 0, 0, 0, 0 ) ); add( styleLabel ); styleLabel.setBackground( new Color( 192, 192, 192 ) ); styleLabel.setForeground( new Color( 0, 0, 0 ) ); styleLabel.setEnabled( true ); styleLabel.setVisible( true ); color1 = new Checkbox( "Yellow", false ); color1.setCheckboxGroup( checkGroup1 ); mainLayout.setConstraints( color1, makeGridCons( 0, 9, 4, 1, 100, 100, GridBagConstraints.BOTH, GridBagConstraints.CENTER, 0, 0, 0, 0, 0, 0 ) ); add( color1 ); color1.setBackground( new Color( 192, 192, 192 ) ); color1.setForeground( new Color( 100, 100, 50 ) ); color1.setEnabled( true ); color1.setVisible( true ); color2 = new Checkbox( "Default", false ); color2.setCheckboxGroup( checkGroup1 ); mainLayout.setConstraints( color2, makeGridCons( 0, 8, 4, 1, 100, 100, GridBagConstraints.BOTH, GridBagConstraints.CENTER, 0, 0, 0, 0, 0, 0 ) ); add( color2 ); color2.setBackground( new Color( 192, 192, 192 ) ); color2.setForeground( new Color( 0, 0, 0 ) ); color2.setEnabled( true ); color2.setVisible( true ); color2.setState(true); color3 = new Checkbox( "Blue", false ); color3.setCheckboxGroup( checkGroup1 ); mainLayout.setConstraints( color3, makeGridCons( 0, 10, 4, 1, 100, 100, GridBagConstraints.BOTH, GridBagConstraints.CENTER, 0, 0, 0, 0, 0, 0 ) ); add( color3 ); color3.setBackground( new Color( 192, 192, 192 ) ); color3.setForeground( new Color( 0, 0, 255 ) ); color3.setEnabled( true ); color3.setVisible( true ); color4 = new Checkbox( "Red", false ); color4.setCheckboxGroup( checkGroup1 ); mainLayout.setConstraints( color4, makeGridCons( 0, 11, 4, 1, 100, 100, GridBagConstraints.BOTH, GridBagConstraints.CENTER, 0, 0, 0, 0, 0, 0 ) ); add( color4 ); color4.setBackground( new Color( 192, 192, 192 ) ); color4.setForeground( new Color( 255, 0, 0 ) ); color4.setEnabled( true ); color4.setVisible( true ); color5 = new Checkbox( "Green", false ); color5.setCheckboxGroup( checkGroup1 ); mainLayout.setConstraints( color5, makeGridCons( 0, 12, 4, 1, 100, 100, GridBagConstraints.BOTH, GridBagConstraints.CENTER, 0, 0, 0, 0, 0, 0 ) ); add( color5 ); color5.setBackground( new Color( 192, 192, 192 ) ); color5.setForeground( new Color( 0, 255, 0 ) ); color5.setEnabled( true ); color5.setVisible( true ); color6 = new Checkbox( "Orange", false ); color6.setCheckboxGroup( checkGroup1 ); mainLayout.setConstraints( color6, makeGridCons( 0, 13, 4, 1, 100, 100, GridBagConstraints.BOTH, GridBagConstraints.CENTER, 0, 0, 0, 0, 0, 0 ) ); add( color6 ); color6.setBackground( new Color( 192, 192, 192 ) ); color6.setForeground( new Color( 50, 50, 50 ) ); color6.setEnabled( true ); color6.setVisible( true ); styleItalics = new Checkbox( "ITALICS", false ); mainLayout.setConstraints( styleItalics, makeGridCons( 0, 3, 9, 1, 100, 100, GridBagConstraints.BOTH, GridBagConstraints.CENTER, 0, 0, 0, 0, 0, 0 ) ); add( styleItalics ); styleItalics.setBackground( new Color( 192, 192, 192 ) ); styleItalics.setForeground( new Color( 0, 0, 0 ) ); styleItalics.setEnabled( true ); styleItalics.setVisible( true ); styleBold = new Checkbox( "BOLD", false ); mainLayout.setConstraints( styleBold, makeGridCons( 0, 2, 9, 1, 100, 100, GridBagConstraints.BOTH, GridBagConstraints.CENTER, 0, 0, 0, 0, 0, 0 ) ); add( styleBold ); styleBold.setBackground( new Color( 192, 192, 192 ) ); styleBold.setForeground( new Color( 0, 0, 0 ) ); styleBold.setEnabled( true ); styleBold.setVisible( true ); styleTeletype = new Checkbox( "TELETYPE", false ); mainLayout.setConstraints( styleTeletype, makeGridCons( 0, 4, 9, 1, 100, 100, GridBagConstraints.BOTH, GridBagConstraints.CENTER, 0, 0, 0, 0, 0, 0 ) ); add( styleTeletype ); styleTeletype.setBackground( new Color( 192, 192, 192 ) ); styleTeletype.setForeground( new Color( 0, 0, 0 ) ); styleTeletype.setEnabled( true ); styleTeletype.setVisible( true ); font1 = new Checkbox( "Default", false ); font1.setCheckboxGroup( checkGroup2 ); mainLayout.setConstraints( font1, makeGridCons( 5, 8, 4, 1, 100, 100, GridBagConstraints.BOTH, GridBagConstraints.CENTER, 0, 0, 0, 0, 0, 0 ) ); add( font1 ); font1.setBackground( new Color( 192, 192, 192 ) ); font1.setForeground( new Color( 0, 0, 0 ) ); font1.setEnabled( true ); font1.setVisible( true ); font1.setState(true); font2 = new Checkbox( "Handwriting", false ); font2.setCheckboxGroup( checkGroup2 ); mainLayout.setConstraints( font2, makeGridCons( 5, 9, 4, 1, 100, 100, GridBagConstraints.BOTH, GridBagConstraints.CENTER, 0, 0, 0, 0, 0, 0 ) ); add( font2 ); font2.setBackground( new Color( 192, 192, 192 ) ); font2.setForeground( new Color( 0, 0, 0 ) ); font2.setEnabled( true ); font2.setVisible( true ); font3 = new Checkbox( "Courier New", false ); font3.setCheckboxGroup( checkGroup2 ); mainLayout.setConstraints( font3, makeGridCons( 5, 10, 4, 1, 100, 100, GridBagConstraints.BOTH, GridBagConstraints.CENTER, 0, 0, 0, 0, 0, 0 ) ); add( font3 ); font3.setBackground( new Color( 192, 192, 192 ) ); font3.setForeground( new Color( 0, 0, 0 ) ); font3.setEnabled( true ); font3.setVisible( true ); pack(); show(); } /*Allows the selection of text that is to have html tags *added to be set */ public void setSelection(String selection) { textSelection = selection; } /*Returns the tags the user has chosen, thru the GUI, *to add to the selected text */ public String getTags() { if (styleBold.getState()) { boldtag = ""; boldtag2 = ""; } if (styleItalics.getState()) { italicstag = ""; italicstag2 = ""; } if (styleTeletype.getState()) { teletypetag = ""; teletypetag2 = ""; } colortag = (""); colortag2 = (""); fonttag = (""); fonttag2 = (""); return (boldtag + italicstag + teletypetag + fonttag + colortag + "\n" + " " + textSelection + "\n" + fonttag2 + colortag2 + boldtag2 + italicstag2 + teletypetag2); } public String getColor() { SimpleOutput out = new SimpleOutput(); out.println((checkGroup1.getSelectedCheckbox()).getLabel()); if ((checkGroup1.getSelectedCheckbox()).getLabel().equals("Red")) { colorselected = "#FF3300"; } if ((checkGroup1.getSelectedCheckbox()).getLabel().equals("Blue")) { colorselected = "#0000FF"; } if ((checkGroup1.getSelectedCheckbox()).getLabel().equals("Green")) { colorselected = "#00CC33"; } if ((checkGroup1.getSelectedCheckbox()).getLabel().equals("Yellow")) { colorselected = "#99FF00"; } if ((checkGroup1.getSelectedCheckbox()).getLabel().equals("Orange")) { colorselected = "#CC3300"; } if ((checkGroup1.getSelectedCheckbox()).getLabel().equals("Default")) { colorselected = "#000000"; } return colorselected; } // -------------------------------------------- // Silly, silly gridbaglayout // -------------------------------------------- public GridBagConstraints makeGridCons( int x, int y, int dx, int dy, int wx, int wy, int fill, int anch, int it, int il, int ib, int ir, int px, int py ) { GridBagConstraints cons = new GridBagConstraints(); // Set the constraints. cons.weightx = wx; cons.weighty = wy; cons.gridx = x; cons.gridy = y; cons.gridwidth = dx; cons.gridheight = dy; cons.fill = fill; cons.anchor = anch; cons.insets = new Insets( it, il, ib, ir ); cons.ipadx = px; cons.ipady = py; // Return the constraints return cons; } // ------------------------ // window listeners // ------------------------ public void windowClosing( WindowEvent event ) { dispose(); } public void windowOpened( WindowEvent event ) {} public void windowIconified( WindowEvent event ) {} public void windowDeiconified( WindowEvent event ) {} public void windowClosed( WindowEvent event ) {} public void windowActivated( WindowEvent event ) {} public void windowDeactivated( WindowEvent event ) {} //public static void main(String args[]) { //textselection = (new try3("Let's change this text")); //} }