# PaletteGenerator.java Sample

This topic inludes the source code for the PaletteGenerator.java Sample.

## Sample Location

This sample is located in the following directory in your WebLogic Workshop installation:

BEA_HOME/weblogic81/samples/workshop/ExtensionDevKit/TaglibExtDevKit/TldxHandlers/TDK/

## Sample Source Code

`001 package TDK; 002 003 import com.bea.ide.Application; 004 import com.bea.ide.jspdesigner.InsertWizard; 005 import com.bea.ide.jspdesigner.PaletteItem; 006 import com.bea.ide.lang.jsp.IDOMDocument; 007 import com.bea.ide.lang.jsp.IDOMNode; 008 import com.bea.ide.lang.jsp.IDOMTextNode; 009 import com.bea.ide.lang.jsp.IJspDocument; 010 import com.bea.ide.lang.jsp.IJspAction; 011 import com.bea.ide.lang.jsp.IJspTaglibDirective; 012 import java.awt.Frame; 013 import java.awt.GridBagConstraints; 014 import java.awt.GridBagLayout; 015 import java.awt.event.ActionEvent; 016 import java.awt.event.ActionListener; 017 import java.awt.event.ComponentAdapter; 018 import java.awt.event.ComponentEvent; 019 import java.beans.PropertyChangeEvent; 020 import java.util.ArrayList; 021 import javax.servlet.jsp.tagext.TagInfo; 022 import javax.swing.AbstractAction; 023 import javax.swing.BorderFactory; 024 import javax.swing.JButton; 025 import javax.swing.JDialog; 026 import javax.swing.JOptionPane; 027 import javax.swing.JPanel; 028 import javax.swing.JTextArea; 029 import java.beans.PropertyChangeListener; 030 import javax.servlet.jsp.tagext.TagLibraryInfo; 031 import javax.swing.JLabel; 032 import javax.swing.JTextField; 033 034 035 public class PaletteGenerator extends com.bea.ide.jspdesigner.PaletteGenerator 036 { 037 public String getLabel() 038 { 039 return ".:TDK tags:."; 040 } 041 042 public int getPriority() 043 { 044 return 10; 045 } 046 047 class DemoPaletteItem extends PaletteItem 048 { 049 private String _label; 050 private IDOMDocument _doc; 051 private TagLibraryInfo _tli; 052 053 public DemoPaletteItem(String label, IDOMDocument doc, TagLibraryInfo tli) 054 { 055 _label = label; 056 _doc = doc; 057 _tli = tli; 058 } 059 public String getLabel() { return ".:" + _label + ":."; } 060 public IDOMDocument getInsertDocument() { return _doc; } 061 062 // attach a custom wizard to the action of dragging the "barcode" tag onto jsp designer. 063 public InsertWizard getInsertWizard() 064 { 065 if(_label.equals("barcode")) 066 { 067 return new DemoBarcodeInsertWizard(_tli); 068 } 069 return null; 070 } 071 } 072 073 class DemoBarcodeInsertWizard extends InsertWizard 074 { 075 private JDialog _dialog; 076 private TagLibraryInfo _tli; 077 078 public DemoBarcodeInsertWizard(TagLibraryInfo tli) 079 { 080 _tli = tli; 081 } 082 083 public IDOMDocument invokeWizard(IDOMNode nodeParent, IDOMNode nodeRefChild) 084 { 085 IDOMDocument docFrag = nodeParent.getOwnerDocument().createCompatibleDocument(); 086 IJspAction el = null; 087 088 JPanel panel = new JPanel(); 089 JTextField textField = new JTextField(15); 090 JLabel label = new JLabel("Yo. Enter snippet to encode in code39 format: "); 091 panel.add(label); 092 panel.add(textField); 093 if(JOptionPane.showConfirmDialog(Application.getRootFrame(), panel, "Demo Insert Wizard", JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE, null) == JOptionPane.OK_OPTION) 094 { 095 // insert a tag into the document with the name <tdk:barcode> 096 el = (IJspAction) docFrag.createElement(IJspAction.class, _tli.getShortName() + ":" + "barcode"); 097 098 // we only support code39 right now. 099 el.setAttribute("encodingType", "code39"); 100 el.setAttribute("value", textField.getText()); 101 102 docFrag.appendChild(el); 103 return docFrag; 104 } 105 106 return null; 107 } 108 } 109 110 public PaletteItem[] getPaletteItems() 111 { 112 TagInfo[] tagInfoArray = getTagLibraryInfo().getTags(); 113 PaletteItem ret[] = new PaletteItem[tagInfoArray.length]; 114 for(int i = 0; i < tagInfoArray.length; i++) 115 { 116 TagInfo tagInfo = tagInfoArray[i]; 117 ret[i] = new DemoPaletteItem(tagInfo.getTagName(), null, getTagLibraryInfo()); 118 } 119 120 return ret; 121 } 122 }`