diff -r 9abe4cd1f308 -r 41e91ea94acb java/rozsirene-atributy-jedit/src/cz/frantovo/rozsireneAtributy/jedit/DokovatelnyPanel.java --- a/java/rozsirene-atributy-jedit/src/cz/frantovo/rozsireneAtributy/jedit/DokovatelnyPanel.java Sat Dec 16 14:48:17 2023 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,140 +0,0 @@ -/** - * Rozšířené atributy – program na správu rozšířených atributů souborů - * Copyright © 2012 František Kučera (frantovo.cz) - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package cz.frantovo.rozsireneAtributy.jedit; - -import cz.frantovo.rozsireneAtributy.gui.Model; -import cz.frantovo.rozsireneAtributy.gui.Panel; -import java.awt.BorderLayout; -import java.io.File; -import java.io.IOException; -import java.util.logging.Level; -import java.util.logging.Logger; -import javax.swing.JOptionPane; -import javax.swing.JPanel; -import org.gjt.sp.jedit.Buffer; -import org.gjt.sp.jedit.EBComponent; -import org.gjt.sp.jedit.EBMessage; -import org.gjt.sp.jedit.EditBus; -import org.gjt.sp.jedit.View; -import org.gjt.sp.jedit.msg.EditPaneUpdate; - -/** - * - * @author Ing. František Kučera (frantovo.cz) - */ -public class DokovatelnyPanel extends JPanel implements EBComponent { - - private static final Logger log = Logger - .getLogger(DokovatelnyPanel.class.getName()); - private View view; - private Panel panel; - - public DokovatelnyPanel(final View view, final String position) { - this.view = view; - setLayout(new BorderLayout()); - změňSoubor(view.getBuffer(), false); - } - - /** - * Zaregistrujeme se, aby nám chodily události editoru. - */ - @Override - public void addNotify() { - super.addNotify(); - EditBus.addToBus(this); - } - - /** - * @see #addNotify() - */ - @Override - public void removeNotify() { - super.removeNotify(); - EditBus.removeFromBus(this); - } - - /** - * Zpracujeme události editoru. Zajímá nás přepnutí na jiný soubor – abychom - * pro něj zobrazili atributy. - * - * @param událost událost editoru - */ - @Override - public void handleMessage(EBMessage událost) { - try { - if (událost instanceof EditPaneUpdate) { - EditPaneUpdate epu = (EditPaneUpdate) událost; - // Chodí nám všechny události - // – potřebujeme filtrovat jen ty pro naše okno. - if (view == epu.getEditPane().getView()) { - // zajímá nás jen přepnutí souboru - if (epu.getWhat() == EditPaneUpdate.BUFFER_CHANGED) { - /** - * TODO: je soubor nově otevřený? - */ - změňSoubor(view.getBuffer(), - epu.getWhat() == EditPaneUpdate.CREATED); - } - } - } - // událost instanceof BufferUpdate - // událost instanceof PropertiesChanged - } catch (Exception e) { - log.log(Level.WARNING, "Chyba při zpracování: " + událost, e); - } - - } - - private void změňSoubor(Buffer b, boolean využijAtributy) { - try { - File s = new File(b.getPath()); - - if (s.isFile() && s.canRead()) { - Model m = new Model(s); - - if (panel == null) { - panel = new Panel(m); - removeAll(); - add(panel, BorderLayout.CENTER); - } else { - panel.setModel(m); - } - - if (využijAtributy) { - využijAtributy(m, b); - } - - } else { - // TODO: zobrazit chybu - log.log(Level.WARNING, - "Soubor neexistuje nebo nemáme práva na čtení: {0}", s); - } - } catch (IOException e) { - log.log(Level.WARNING, "Chyba při změně souboru.", e); - } - } - - /** - * Nastaví jEdit podle atributů daného souboru: - odsazování - kódování - * - * @param m model obsahující atributy - * @param b soubor otevřený v editoru - */ - private void využijAtributy(Model m, Buffer b) { - JOptionPane.showMessageDialog(panel, "Nový soubor!"); - } -}