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
Myra WebTools - HtmlWidget.java

HtmlWidget.java

Caricato da: Ht-never
Scarica il programma completo

  1. import javax.swing.*;
  2. import javax.swing.text.html.HTMLEditorKit;
  3.  
  4. import Func.Global;
  5.  
  6. import java.awt.*;
  7. import java.awt.event.*;
  8.  
  9. @SuppressWarnings({ "serial", "unused" })
  10. public class HtmlWidget extends JPanel implements
  11.         JEditorPane label = new JEditorPane();
  12.     JTextArea htmlTextArea = new JTextArea();
  13.     ClipboardPopupMenu pop = ClipboardPopupMenu.installForComponent(label);
  14.     ClipboardPopupMenu cpb = ClipboardPopupMenu.installForComponent(label);
  15.     public HtmlWidget() {
  16.         setLayout(/**new BoxLayout(this, BoxLayout.LINE_AXIS)**/null);
  17.         label.setEditorKit(new HTMLEditorKit());
  18.         String initialText = Global.HtmlTextEsempio;
  19.  
  20.         htmlTextArea = new JTextArea(15, 10);
  21.         htmlTextArea.setText(initialText);
  22.             pop.addCopyFunction("Copia");
  23.             pop.addCutFunction("Taglia");
  24.             pop.addPasteFunction("Incolla");
  25.             pop.addClearFunction("Clear");
  26.             cpb.addCopyFunction("Copia");
  27.             cpb.addCutFunction("Taglia");
  28.             cpb.addPasteFunction("Incolla");
  29.             cpb.addClearFunction("Clear");
  30.         JScrollPane scrollPane = new JScrollPane(htmlTextArea);
  31.         JButton save = new JButton("Save It");
  32.  
  33.         JButton changeTheLabel = new JButton("Preview");
  34.         changeTheLabel.setMnemonic(KeyEvent.VK_C);
  35.         changeTheLabel.setAlignmentX(Component.CENTER_ALIGNMENT);
  36.         changeTheLabel.addActionListener(this);
  37.         save.addActionListener(this);
  38.         save.setMnemonic(KeyEvent.VK_C);
  39.         save.setAlignmentX(Component.CENTER_ALIGNMENT);
  40.  
  41.         label.setText(initialText);
  42.         JPanel leftPanel = new JPanel();
  43.         leftPanel.setLayout(new BoxLayout(leftPanel, BoxLayout.PAGE_AXIS));
  44.         leftPanel.setBorder(BorderFactory.createCompoundBorder(
  45.                 BorderFactory.createTitledBorder(
  46.                     "HTML Visual Editor"),
  47.                 BorderFactory.createEmptyBorder(10,10,10,10)));
  48.         leftPanel.add(scrollPane);
  49.         leftPanel.add(Box.createRigidArea(new Dimension(0,10)));
  50.         leftPanel.add(changeTheLabel);
  51.         leftPanel.add(save);
  52.        
  53.         leftPanel.setBackground(Color.gray);
  54.  
  55.         JPanel rightPanel = new JPanel();
  56.         rightPanel.setLayout(new BoxLayout(rightPanel, BoxLayout.PAGE_AXIS));
  57.         rightPanel.setBorder(BorderFactory.createCompoundBorder(
  58.                         BorderFactory.createTitledBorder("Preview HTML"),
  59.                         BorderFactory.createEmptyBorder(10,10,10,10)));
  60.         rightPanel.setBackground(Color.gray);
  61.         rightPanel.add(label);
  62.  
  63.        
  64.        
  65.         setBorder(BorderFactory.createEmptyBorder(10,10,10,10));
  66.         add(leftPanel);
  67.         add(Box.createRigidArea(new Dimension(5,0)));
  68.         add(rightPanel);
  69.        
  70.         leftPanel.setBounds(15,20,320,480);
  71.         rightPanel.setBounds(342,20,340,480);
  72.     }
  73.  
  74.     // Eventi... Eventi... Ancora Eventi...
  75.     public void actionPerformed(ActionEvent e) {
  76.         if(e.getActionCommand().compareTo("Preview")==0) {
  77.             label.setText(htmlTextArea.getText());
  78.         }
  79.         if(e.getActionCommand().compareTo("Save It")==0) {
  80.                         SaveFileWindow s_file=new SaveFileWindow(htmlTextArea.getText());
  81.         }
  82.     }
  83.    
  84.     private static void createAndShowGUI() {
  85.         //Create and set up the window.
  86.         JFrame frame = new JFrame("HtmlDemo");
  87.         frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  88.  
  89.         //Add content to the window.
  90.         frame.add(new HtmlWidget());
  91.  
  92.         //Display the window.
  93.         frame.pack();
  94.         frame.setVisible(true);
  95.     }
  96.  
  97.     public static void Run() {
  98.         SwingUtilities.invokeLater(new Runnable() {
  99.             public void run() {
  100.                 UIManager.put("swing.boldMetal", Boolean.FALSE);
  101.                 createAndShowGUI();
  102.             }
  103.         });
  104.     }
  105.    
  106. }