java/rozsirene-atributy-jedit/src/cz/frantovo/rozsireneAtributy/jedit/DokovatelnyPanel.java
branchv_0
changeset 38 41e91ea94acb
parent 37 9abe4cd1f308
child 39 ec0e970e0830
     1.1 --- a/java/rozsirene-atributy-jedit/src/cz/frantovo/rozsireneAtributy/jedit/DokovatelnyPanel.java	Sat Dec 16 14:48:17 2023 +0100
     1.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.3 @@ -1,140 +0,0 @@
     1.4 -/**
     1.5 - * Rozšířené atributy – program na správu rozšířených atributů souborů
     1.6 - * Copyright © 2012 František Kučera (frantovo.cz)
     1.7 - *
     1.8 - * This program is free software: you can redistribute it and/or modify
     1.9 - * it under the terms of the GNU General Public License as published by
    1.10 - * the Free Software Foundation, either version 3 of the License.
    1.11 - *
    1.12 - * This program is distributed in the hope that it will be useful,
    1.13 - * but WITHOUT ANY WARRANTY; without even the implied warranty of
    1.14 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
    1.15 - * GNU General Public License for more details.
    1.16 - *
    1.17 - * You should have received a copy of the GNU General Public License
    1.18 - * along with this program. If not, see <http://www.gnu.org/licenses/>.
    1.19 - */
    1.20 -package cz.frantovo.rozsireneAtributy.jedit;
    1.21 -
    1.22 -import cz.frantovo.rozsireneAtributy.gui.Model;
    1.23 -import cz.frantovo.rozsireneAtributy.gui.Panel;
    1.24 -import java.awt.BorderLayout;
    1.25 -import java.io.File;
    1.26 -import java.io.IOException;
    1.27 -import java.util.logging.Level;
    1.28 -import java.util.logging.Logger;
    1.29 -import javax.swing.JOptionPane;
    1.30 -import javax.swing.JPanel;
    1.31 -import org.gjt.sp.jedit.Buffer;
    1.32 -import org.gjt.sp.jedit.EBComponent;
    1.33 -import org.gjt.sp.jedit.EBMessage;
    1.34 -import org.gjt.sp.jedit.EditBus;
    1.35 -import org.gjt.sp.jedit.View;
    1.36 -import org.gjt.sp.jedit.msg.EditPaneUpdate;
    1.37 -
    1.38 -/**
    1.39 - *
    1.40 - * @author Ing. František Kučera (frantovo.cz)
    1.41 - */
    1.42 -public class DokovatelnyPanel extends JPanel implements EBComponent {
    1.43 -
    1.44 -	private static final Logger log = Logger
    1.45 -		.getLogger(DokovatelnyPanel.class.getName());
    1.46 -	private View view;
    1.47 -	private Panel panel;
    1.48 -
    1.49 -	public DokovatelnyPanel(final View view, final String position) {
    1.50 -		this.view = view;
    1.51 -		setLayout(new BorderLayout());
    1.52 -		změňSoubor(view.getBuffer(), false);
    1.53 -	}
    1.54 -
    1.55 -	/**
    1.56 -	 * Zaregistrujeme se, aby nám chodily události editoru.
    1.57 -	 */
    1.58 -	@Override
    1.59 -	public void addNotify() {
    1.60 -		super.addNotify();
    1.61 -		EditBus.addToBus(this);
    1.62 -	}
    1.63 -
    1.64 -	/**
    1.65 -	 * @see #addNotify()
    1.66 -	 */
    1.67 -	@Override
    1.68 -	public void removeNotify() {
    1.69 -		super.removeNotify();
    1.70 -		EditBus.removeFromBus(this);
    1.71 -	}
    1.72 -
    1.73 -	/**
    1.74 -	 * Zpracujeme události editoru. Zajímá nás přepnutí na jiný soubor – abychom
    1.75 -	 * pro něj zobrazili atributy.
    1.76 -	 *
    1.77 -	 * @param událost událost editoru
    1.78 -	 */
    1.79 -	@Override
    1.80 -	public void handleMessage(EBMessage událost) {
    1.81 -		try {
    1.82 -			if (událost instanceof EditPaneUpdate) {
    1.83 -				EditPaneUpdate epu = (EditPaneUpdate) událost;
    1.84 -				// Chodí nám všechny události
    1.85 -				// – potřebujeme filtrovat jen ty pro naše okno.
    1.86 -				if (view == epu.getEditPane().getView()) {
    1.87 -					// zajímá nás jen přepnutí souboru
    1.88 -					if (epu.getWhat() == EditPaneUpdate.BUFFER_CHANGED) {
    1.89 -						/**
    1.90 -						 * TODO: je soubor nově otevřený?
    1.91 -						 */
    1.92 -						změňSoubor(view.getBuffer(),
    1.93 -							epu.getWhat() == EditPaneUpdate.CREATED);
    1.94 -					}
    1.95 -				}
    1.96 -			}
    1.97 -			// událost instanceof BufferUpdate
    1.98 -			// událost instanceof PropertiesChanged
    1.99 -		} catch (Exception e) {
   1.100 -			log.log(Level.WARNING, "Chyba při zpracování: " + událost, e);
   1.101 -		}
   1.102 -
   1.103 -	}
   1.104 -
   1.105 -	private void změňSoubor(Buffer b, boolean využijAtributy) {
   1.106 -		try {
   1.107 -			File s = new File(b.getPath());
   1.108 -
   1.109 -			if (s.isFile() && s.canRead()) {
   1.110 -				Model m = new Model(s);
   1.111 -
   1.112 -				if (panel == null) {
   1.113 -					panel = new Panel(m);
   1.114 -					removeAll();
   1.115 -					add(panel, BorderLayout.CENTER);
   1.116 -				} else {
   1.117 -					panel.setModel(m);
   1.118 -				}
   1.119 -
   1.120 -				if (využijAtributy) {
   1.121 -					využijAtributy(m, b);
   1.122 -				}
   1.123 -
   1.124 -			} else {
   1.125 -				// TODO: zobrazit chybu
   1.126 -				log.log(Level.WARNING,
   1.127 -					"Soubor neexistuje nebo nemáme práva na čtení: {0}", s);
   1.128 -			}
   1.129 -		} catch (IOException e) {
   1.130 -			log.log(Level.WARNING, "Chyba při změně souboru.", e);
   1.131 -		}
   1.132 -	}
   1.133 -
   1.134 -	/**
   1.135 -	 * Nastaví jEdit podle atributů daného souboru: - odsazování - kódování
   1.136 -	 *
   1.137 -	 * @param m model obsahující atributy
   1.138 -	 * @param b soubor otevřený v editoru
   1.139 -	 */
   1.140 -	private void využijAtributy(Model m, Buffer b) {
   1.141 -		JOptionPane.showMessageDialog(panel, "Nový soubor!");
   1.142 -	}
   1.143 -}