Thingamablog 1.0.6 Wikilink + ISCIM extension

Back to program page

Details on version 1.0.3

The new version is an accommodation of a request from a Wikilink user, who wished for having a Wikilink dialog which is more similar to the original hyperlink dialog. Now the dialog also offers fields for Name, Title and Open link in....

Screenshots

The new, extended Wikilink dialog

How to develop it
To extend the dialog, you just have to replace the source code in one file of your already installed Wikilink-extended Thingamablog version, namely WikilinkDialog.java:

/* * WikiLinkDialog.java
 *
 * Created on October 2, 2007, 5:34 PM by Fabian Voith
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package net.sf.thingamablog.gui.editor;

import java.awt.BorderLayout;
import java.awt.Frame;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.BorderFactory;
import javax.swing.JCheckBox;
import javax.swing.JComboBox;
import javax.swing.JPanel;
import javax.swing.JTextField;

import net.sf.thingamablog.TBGlobals;
import net.sf.thingamablog.Utils;
import net.sf.thingamablog.blog.BlogEntry;
import net.sf.thingamablog.blog.Weblog;
import net.sf.thingamablog.gui.LabelledItemPanel;
import net.sf.thingamablog.gui.Messages;



public class WikiLinkDialog extends HTMLOptionDialog
{
  private static final String RES = TBGlobals.RESOURCES;  

  // due to the wish of a user, I extended the WikiLink dialog:
  private static final String NEW_WIN = "New Window"; //$NON-NLS-1$
  private static final String SAME_WIN = "Same Window"; //$NON-NLS-1$
  private static final String SAME_FRAME = "Same Frame"; //$NON-NLS-1$
  private static final String TARGETS[] ={NEW_WIN, SAME_WIN, SAME_FRAME};

  private JComboBox targetCombo;
  private JCheckBox targetCb;
  private JTextField txtName = new JTextField(25);    
  private JTextField txtTitle = new JTextField(25); 

  private JComboBox entryCombo;
  private JTextField txtDesc = new JTextField(25);   

  private String[] urls;

  public WikiLinkDialog(Frame parent, String[] titles, String[] urls)
  {
    super(parent, Messages.getString("EntryEditor.Wikilink"), Utils.createIcon(RES + "wikibig.png"));

    // make information accessible for whole class
    this.urls = urls;

    LabelledItemPanel lip = new LabelledItemPanel();        
    JPanel main = new JPanel(new BorderLayout());

    TextEditPopupManager pm = new TextEditPopupManager();
    pm.addJTextComponent(txtName);
    pm.addJTextComponent(txtTitle);
    pm.addJTextComponent(txtDesc);

    entryCombo = new JComboBox(titles);

    lip.addItem(Messages.getString("WikiDialog.Entry"), entryCombo);
    lip.addItem(Messages.getString("LinkDialog.Name"), txtName);
    lip.addItem(Messages.getString("LinkDialog.Title"), txtTitle);
    lip.addItem(Messages.getString("WikiDialog.Text"), txtDesc);

    targetCb = new JCheckBox(Messages.getString("LinkDialog.Open_link_in")); //$NON-NLS-1$
    targetCombo = new JComboBox(TARGETS);
    JPanel targetPanel = new JPanel(new BorderLayout(5, 5));
    targetPanel.add(targetCb, BorderLayout.WEST);
    targetPanel.add(targetCombo, BorderLayout.CENTER);
    targetPanel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
    targetCb.addActionListener(new ActionListener()
    {
      public void actionPerformed(ActionEvent e)
      {
        updateTargetState();    
      }
    });

    entryCombo.addActionListener(new ActionListener()
    {
      public void actionPerformed(ActionEvent e)
      {
        updateNameBox();
      }
    });

    updateNameBox();
    updateTargetState();

    main.add(lip, BorderLayout.CENTER);
    main.add(targetPanel, BorderLayout.SOUTH);

    setContentPanel(main);
    pack();
    setResizable(false);
  }

  private void updateNameBox()
  {
    boolean isdiff = true;
    if (!txtDesc.getText().equals("")) // only check if textbox not empty
    {
      for (int i = 0; i < entryCombo.getItemCount(); i++) {
        if (entryCombo.getItemAt(i).equals(txtDesc.getText()))
        {
          isdiff = false;
          break;
        }
      }
    } else {
      isdiff = false;
    }

    if (!isdiff) // only update if no user-defined text in txtDesc
    {
      // update contents
      txtDesc.setText((String)entryCombo.getSelectedItem());
    }
  }

  private void updateTargetState()
  {
    targetCombo.setEnabled(targetCb.isSelected());
  }

  public void setLinkDescription(String s)
  {
    txtDesc.setText(s);
  }

  public String getHTML()
  {

    // create html data
    String aTag = "<a href=\""+urls[entryCombo.getSelectedIndex()]+"\"";  //>"+txtDesc.getText()+"</a>";
    if (txtName.getText().length() > 0) {
      aTag += " name=\"" + txtName.getText() + "\"";
    }
    if (txtTitle.getText().length() > 0) {
      aTag += " title=\"" + txtTitle.getText() + "\"";
    }
    if(targetCb.isSelected()) {
      aTag += " target=\""; //$NON-NLS-1$
      if(targetCombo.getSelectedItem() == NEW_WIN) {
        aTag += "_blank"; //$NON-NLS-1$
      } else if (targetCombo.getSelectedItem() == SAME_WIN) {
        aTag += "_top"; //$NON-NLS-1$
      } else if(targetCombo.getSelectedItem() == SAME_FRAME) {
        aTag += "_self"; //$NON-NLS-1$
      }
      aTag += "\""; //$NON-NLS-1$
    }
    aTag += ">" + txtDesc.getText() + "</a>";
    return aTag;
  }
}

Compile the new version and you are ready!