/*
* CustomHyperlinkDialog.java
*
* Created on 27 febbraio 2006, 15.05
*/
/**
*
* @author Vassil Boyadjiev
*/
import javax.swing.JDialog;
import javax.swing.JFrame;
public class CustomHyperlinkDialog extends javax.swing.JDialog implements sferyx.administration.editors.extensions.BrowsableComponent {
/** Creates new form CustomHyperlinkDialog */
public CustomHyperlinkDialog(java.awt.Frame parent, boolean modal) {
super(parent, modal);
initComponents();
setModal(true);
setLocation(200,220);
setSize(480,220);
}
public CustomHyperlinkDialog(JDialog parent, boolean modal) {
super(parent, modal);
initComponents();
setModal(true);
setLocation(200,220);
setSize(480,220);
}
/** 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.
*/
private void initComponents() {//GEN-BEGIN:initComponents
Label1 = new javax.swing.JLabel();
urlTextField = new javax.swing.JTextField();
okButton = new javax.swing.JButton();
cancelButton = new javax.swing.JButton();
Label2 = new javax.swing.JLabel();
getContentPane().setLayout(null);
setTitle("Custom hyperlinks dialog");
setResizable(false);
addWindowListener(new java.awt.event.WindowAdapter() {
public void windowClosing(java.awt.event.WindowEvent evt) {
closeDialog(evt);
}
});
Label1.setFont(new java.awt.Font("Dialog", 1, 14));
Label1.setText("<html>This is a demonstration of a custom browsable component<br> for hyperlinks:</html>");
getContentPane().add(Label1);
Label1.setBounds(30, 20, 430, 50);
urlTextField.setText("Type here a sample string that will be inserted as a link location");
getContentPane().add(urlTextField);
urlTextField.setBounds(30, 110, 400, 20);
okButton.setText("Ok");
okButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
okButtonActionPerformed(evt);
}
});
getContentPane().add(okButton);
okButton.setBounds(270, 150, 70, 26);
cancelButton.setText("Cancel");
cancelButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
cancelButtonActionPerformed(evt);
}
});
getContentPane().add(cancelButton);
cancelButton.setBounds(360, 150, 73, 26);
Label2.setText("You can provide any custom implementation for browsing");
getContentPane().add(Label2);
Label2.setBounds(30, 80, 380, 16);
pack();
}//GEN-END:initComponents
private void cancelButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cancelButtonActionPerformed
// Add your handling code here:
cancel=true;
// setVisible(false);
dispose();
}//GEN-LAST:event_cancelButtonActionPerformed
private void okButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_okButtonActionPerformed
// Add your handling code here:
cancel=false;
// setVisible(false);
dispose();
}//GEN-LAST:event_okButtonActionPerformed
/** Closes the dialog */
private void closeDialog(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_closeDialog
// setVisible(false);
dispose();
}//GEN-LAST:event_closeDialog
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
// new CustomHyperlinkDialog(new javax.swing.JFrame(), true).show();
JDialog frame=new JDialog();
sferyx.administration.editors.HTMLEditor htmlEditor=new sferyx.administration.editors.HTMLEditor();
htmlEditor.setHyperlinkCustomBrowsableComponent(new CustomHyperlinkDialog(frame,true));
CustomHyperlinkDialog imageBrowsable=new CustomHyperlinkDialog(frame,true);
//let's make it a bit different
imageBrowsable.setBackground(java.awt.Color.red);
htmlEditor.setImageCustomBrowsableComponent(imageBrowsable);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.getContentPane().setLayout(new java.awt.BorderLayout());
frame.getContentPane().add(htmlEditor);
frame.setSize(800,600);
frame.show();
}
boolean cancel=false;
/** This method should return the value to be inserted as URL for inserting hyperlinks or images.
*/
public String getResultingURL()
{
if(!cancel) return urlTextField.getText();
return ""; // you can return what you like. When isActionCancelled rturns true the editor will ignore it and the value will remain unchanged
}
/** This method should return the value to be inserted as URL for inserting hyperlinks or images.
*/
public boolean isActionCancelled()
{
return cancel;
}
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JTextField urlTextField;
private javax.swing.JLabel Label2;
private javax.swing.JButton okButton;
private javax.swing.JButton cancelButton;
private javax.swing.JLabel Label1;
// End of variables declaration//GEN-END:variables
}