java/rozsirene-atributy-jedit/src/cz/frantovo/rozsireneAtributy/jedit/DokovatelnyPanel.java
author František Kučera <franta-hg@frantovo.cz>
Sat Aug 18 13:22:45 2012 +0200 (2012-08-18)
changeset 18 907c5c7c20ce
child 19 c20edbed09c3
permissions -rw-r--r--
Doplněk pro jEdit – základ.
     1 package cz.frantovo.rozsireneAtributy.jedit;
     2 
     3 import java.util.logging.Level;
     4 import java.util.logging.Logger;
     5 import javax.swing.JPanel;
     6 import javax.swing.JTextArea;
     7 import org.gjt.sp.jedit.Buffer;
     8 import org.gjt.sp.jedit.EBComponent;
     9 import org.gjt.sp.jedit.EBMessage;
    10 import org.gjt.sp.jedit.EditBus;
    11 import org.gjt.sp.jedit.View;
    12 import org.gjt.sp.jedit.msg.EditPaneUpdate;
    13 
    14 /**
    15  *
    16  * @author Ing. František Kučera (frantovo.cz)
    17  */
    18 public class DokovatelnyPanel extends JPanel implements EBComponent {
    19 
    20 	private static final Logger log = Logger.getLogger(DokovatelnyPanel.class.getName());
    21 	private JTextArea pokus = new JTextArea("...");
    22 	private View view;
    23 
    24 	public DokovatelnyPanel(final View view, final String position) {
    25 		this.view = view;
    26 		add(pokus);
    27 	}
    28 
    29 	/**
    30 	 * Zaregistrujeme se, aby nám chodily události editoru.
    31 	 */
    32 	@Override
    33 	public void addNotify() {
    34 		super.addNotify();
    35 		EditBus.addToBus(this);
    36 	}
    37 
    38 	/**
    39 	 * @see #addNotify()
    40 	 */
    41 	@Override
    42 	public void removeNotify() {
    43 		super.removeNotify();
    44 		EditBus.removeFromBus(this);
    45 	}
    46 
    47 	/**
    48 	 * Zpracujeme události editoru.
    49 	 * Zajímá nás přepnutí na jiný soubor – abychom pro něj zobrazili atributy.
    50 	 *
    51 	 * @param událost událost editoru
    52 	 */
    53 	@Override
    54 	public void handleMessage(EBMessage událost) {
    55 		try {
    56 			if (událost instanceof EditPaneUpdate) {
    57 				EditPaneUpdate epu = (EditPaneUpdate) událost;
    58 				// Chodí nám všechny události – potřebujeme filtrovat jen ty pro naše okno.
    59 				if (view == epu.getEditPane().getView()) {
    60 					změňSoubor(view.getBuffer());
    61 				}
    62 			}
    63 			// událost instanceof BufferUpdate
    64 			// událost instanceof PropertiesChanged
    65 		} catch (Exception e) {
    66 			log.log(Level.WARNING, "Chyba při zpracování události: " + událost, e);
    67 		}
    68 
    69 	}
    70 
    71 	private void změňSoubor(Buffer b) {
    72 		pokus.setText(b.getPath());
    73 	}
    74 }