java/rozsirene-atributy-jedit/src/cz/frantovo/rozsireneAtributy/jedit/DokovatelnyPanel.java
author František Kučera <franta-hg@frantovo.cz>
Sat Aug 18 13:27:00 2012 +0200 (2012-08-18)
changeset 19 c20edbed09c3
parent 18 907c5c7c20ce
child 20 bf328b110881
permissions -rw-r--r--
informace o licenci uvnitř .java souborů
     1 /**
     2  * Rozšířené atributy – program na správu rozšířených atributů souborů
     3  * Copyright © 2012 František Kučera (frantovo.cz)
     4  * 
     5  * This program is free software: you can redistribute it and/or modify
     6  * it under the terms of the GNU General Public License as published by
     7  * the Free Software Foundation, either version 3 of the License, or
     8  * (at your option) any later version.
     9  * 
    10  * This program is distributed in the hope that it will be useful,
    11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
    12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    13  * GNU General Public License for more details.
    14  * 
    15  * You should have received a copy of the GNU General Public License
    16  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
    17  */
    18 package cz.frantovo.rozsireneAtributy.jedit;
    19 
    20 import java.util.logging.Level;
    21 import java.util.logging.Logger;
    22 import javax.swing.JPanel;
    23 import javax.swing.JTextArea;
    24 import org.gjt.sp.jedit.Buffer;
    25 import org.gjt.sp.jedit.EBComponent;
    26 import org.gjt.sp.jedit.EBMessage;
    27 import org.gjt.sp.jedit.EditBus;
    28 import org.gjt.sp.jedit.View;
    29 import org.gjt.sp.jedit.msg.EditPaneUpdate;
    30 
    31 /**
    32  *
    33  * @author Ing. František Kučera (frantovo.cz)
    34  */
    35 public class DokovatelnyPanel extends JPanel implements EBComponent {
    36 
    37 	private static final Logger log = Logger.getLogger(DokovatelnyPanel.class.getName());
    38 	private JTextArea pokus = new JTextArea("...");
    39 	private View view;
    40 
    41 	public DokovatelnyPanel(final View view, final String position) {
    42 		this.view = view;
    43 		add(pokus);
    44 	}
    45 
    46 	/**
    47 	 * Zaregistrujeme se, aby nám chodily události editoru.
    48 	 */
    49 	@Override
    50 	public void addNotify() {
    51 		super.addNotify();
    52 		EditBus.addToBus(this);
    53 	}
    54 
    55 	/**
    56 	 * @see #addNotify()
    57 	 */
    58 	@Override
    59 	public void removeNotify() {
    60 		super.removeNotify();
    61 		EditBus.removeFromBus(this);
    62 	}
    63 
    64 	/**
    65 	 * Zpracujeme události editoru.
    66 	 * Zajímá nás přepnutí na jiný soubor – abychom pro něj zobrazili atributy.
    67 	 *
    68 	 * @param událost událost editoru
    69 	 */
    70 	@Override
    71 	public void handleMessage(EBMessage událost) {
    72 		try {
    73 			if (událost instanceof EditPaneUpdate) {
    74 				EditPaneUpdate epu = (EditPaneUpdate) událost;
    75 				// Chodí nám všechny události – potřebujeme filtrovat jen ty pro naše okno.
    76 				if (view == epu.getEditPane().getView()) {
    77 					změňSoubor(view.getBuffer());
    78 				}
    79 			}
    80 			// událost instanceof BufferUpdate
    81 			// událost instanceof PropertiesChanged
    82 		} catch (Exception e) {
    83 			log.log(Level.WARNING, "Chyba při zpracování události: " + událost, e);
    84 		}
    85 
    86 	}
    87 
    88 	private void změňSoubor(Buffer b) {
    89 		pokus.setText(b.getPath());
    90 	}
    91 }