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