Questo sito utilizza cookies solo per scopi di autenticazione sul sito e nient'altro. Nessuna informazione personale viene tracciata. Leggi l'informativa sui cookies.
Username: Password: oppure
JHtmlImageMapper - HTMLdialog.java

HTMLdialog.java

Caricato da: GN
Scarica il programma completo

  1. import java.awt.*;
  2. import java.awt.event.*;
  3. import java.awt.datatransfer.StringSelection;
  4. import java.awt.datatransfer.Clipboard;
  5. import javax.swing.*;
  6. import java.util.List;
  7. import areas.*;
  8.  
  9. public class HTMLdialog extends JDialog implements ActionListener{
  10.  
  11.         JTextArea textArea = new JTextArea();
  12.         JButton copy = new JButton("Copy to clipboard");
  13.         JButton close = new JButton("Close");
  14.  
  15.         public HTMLdialog(Frame owner, List<Area> areas){
  16.                 super(owner, "HTML code for image map", true);
  17.                 setSize(640, 480);
  18.                 setDefaultCloseOperation(DISPOSE_ON_CLOSE);
  19.                 textArea.setEditable(false);
  20.                 String s = "<img src='path/to/image.ext' usemap='#imgmap'>\n<map name='imgmap'>\n";
  21.                 for(Area a: areas){
  22.                         s += " " + a.getHTML() + "\n";
  23.                 }
  24.                 s += "</map>";
  25.                 textArea.setText(s);
  26.                 setLayout(new BorderLayout());
  27.                 add(textArea, BorderLayout.CENTER);
  28.                 JPanel p = new JPanel(new GridLayout(1, 2, 5, 5));
  29.                 p.add(copy);
  30.                 p.add(close);
  31.                 add(p, BorderLayout.SOUTH);
  32.                 copy.addActionListener(this);
  33.                 close.addActionListener(this);
  34.         }
  35.  
  36.         public void actionPerformed(ActionEvent e){
  37.                 if(e.getSource() == copy){
  38.                         StringSelection s = new StringSelection(textArea.getText());
  39.                         Clipboard c = Toolkit.getDefaultToolkit().getSystemClipboard();
  40.                         c.setContents(s, s);
  41.                         JOptionPane.showMessageDialog(this, "Code copied to clipboard.");
  42.                 }else if(e.getSource() == close){
  43.                         dispatchEvent(new WindowEvent(this, WindowEvent.WINDOW_CLOSING));
  44.                 }
  45.         }
  46. }