| /* |
| * To change this template, choose Tools | Templates |
| * and open the template in the editor. |
| */ |
| package de.word.editor.core; |
| |
| import de.word.editor.api.WordEditorInterface; |
| import java.awt.event.ActionEvent; |
| import java.awt.event.ActionListener; |
| import java.util.Collection; |
| import javax.swing.DefaultComboBoxModel; |
| import org.openide.util.NbBundle; |
| import org.openide.windows.TopComponent; |
| import org.netbeans.api.settings.ConvertAsProperties; |
| import org.openide.awt.ActionID; |
| import org.openide.awt.ActionReference; |
| import org.openide.util.Lookup; |
| |
| /** |
| * Top component which displays something. |
| */ |
| @ConvertAsProperties(dtd = "-//de.word.editor.core//WordEditor//EN", |
| autostore = false) |
| @TopComponent.Description(preferredID = "WordEditorTopComponent", |
| //iconBase="SET/PATH/TO/ICON/HERE", |
| persistenceType = TopComponent.PERSISTENCE_ALWAYS) |
| @TopComponent.Registration(mode = "editor", openAtStartup = true) |
| @ActionID(category = "Window", id = "de.word.editor.core.WordEditorTopComponent") |
| @ActionReference(path = "Menu/Window" /*, position = 333 */) |
| @TopComponent.OpenActionRegistration(displayName = "#CTL_WordEditorAction", |
| preferredID = "WordEditorTopComponent") |
| public final class WordEditorTopComponent extends TopComponent { |
| |
| public WordEditorTopComponent() { |
| initComponents(); |
| setName(NbBundle.getMessage(WordEditorTopComponent.class, "CTL_WordEditorTopComponent")); |
| setToolTipText(NbBundle.getMessage(WordEditorTopComponent.class, "HINT_WordEditorTopComponent")); |
| |
| DefaultComboBoxModel dcbm = new DefaultComboBoxModel(); |
| |
| Collection<? extends WordEditorInterface> allWESvcs = |
| Lookup.getDefault().lookupAll(WordEditorInterface.class); |
| |
| for (WordEditorInterface wordEditorInterface : allWESvcs) { |
| dcbm.addElement(wordEditorInterface); |
| } |
| |
| jComboBox1.setModel(dcbm); |
| |
| jButton1.addActionListener(new ActionListener() { |
| |
| @Override |
| public void actionPerformed(ActionEvent e) { |
| String enteredText = jTextField1.getText(); |
| WordEditorInterface selectedFilter = (WordEditorInterface) jComboBox1.getSelectedItem(); |
| String processedText = selectedFilter.process(enteredText); |
| jTextArea1.setText(processedText); |
| } |
| }); |
| |
| |
| } |
| |
| /** 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. |
| */ |
| // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents |
| private void initComponents() { |
| |
| jLabel1 = new javax.swing.JLabel(); |
| jScrollPane1 = new javax.swing.JScrollPane(); |
| jTextArea1 = new javax.swing.JTextArea(); |
| jTextField1 = new javax.swing.JTextField(); |
| jButton1 = new javax.swing.JButton(); |
| jComboBox1 = new javax.swing.JComboBox(); |
| |
| org.openide.awt.Mnemonics.setLocalizedText(jLabel1, org.openide.util.NbBundle.getMessage(WordEditorTopComponent.class, "WordEditorTopComponent.jLabel1.text")); // NOI18N |
| |
| jTextArea1.setColumns(20); |
| jTextArea1.setRows(5); |
| jScrollPane1.setViewportView(jTextArea1); |
| |
| jTextField1.setText(org.openide.util.NbBundle.getMessage(WordEditorTopComponent.class, "WordEditorTopComponent.jTextField1.text")); // NOI18N |
| |
| org.openide.awt.Mnemonics.setLocalizedText(jButton1, org.openide.util.NbBundle.getMessage(WordEditorTopComponent.class, "WordEditorTopComponent.jButton1.text")); // NOI18N |
| |
| jComboBox1.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" })); |
| |
| javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this); |
| this.setLayout(layout); |
| layout.setHorizontalGroup( |
| layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) |
| .addGroup(layout.createSequentialGroup() |
| .addContainerGap() |
| .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) |
| .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 429, Short.MAX_VALUE) |
| .addGroup(layout.createSequentialGroup() |
| .addComponent(jLabel1) |
| .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) |
| .addComponent(jTextField1, javax.swing.GroupLayout.DEFAULT_SIZE, 332, Short.MAX_VALUE) |
| .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) |
| .addComponent(jButton1)) |
| .addComponent(jComboBox1, 0, 429, Short.MAX_VALUE)) |
| .addContainerGap()) |
| ); |
| layout.setVerticalGroup( |
| layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) |
| .addGroup(layout.createSequentialGroup() |
| .addContainerGap() |
| .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) |
| .addComponent(jLabel1) |
| .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) |
| .addComponent(jButton1)) |
| .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) |
| .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 227, Short.MAX_VALUE) |
| .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) |
| .addComponent(jComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) |
| .addContainerGap()) |
| ); |
| }// </editor-fold>//GEN-END:initComponents |
| |
| // Variables declaration - do not modify//GEN-BEGIN:variables |
| private javax.swing.JButton jButton1; |
| private javax.swing.JComboBox jComboBox1; |
| private javax.swing.JLabel jLabel1; |
| private javax.swing.JScrollPane jScrollPane1; |
| private javax.swing.JTextArea jTextArea1; |
| private javax.swing.JTextField jTextField1; |
| // End of variables declaration//GEN-END:variables |
| @Override |
| public void componentOpened() { |
| // TODO add custom code on component opening |
| } |
| |
| @Override |
| public void componentClosed() { |
| // TODO add custom code on component closing |
| } |
| |
| void writeProperties(java.util.Properties p) { |
| // better to version settings since initial version as advocated at |
| // http://wiki.apidesign.org/wiki/PropertyFiles |
| p.setProperty("version", "1.0"); |
| // TODO store your settings |
| } |
| |
| void readProperties(java.util.Properties p) { |
| String version = p.getProperty("version"); |
| // TODO read your settings according to their version |
| } |
| } |