/*
* Die Aenderungen hab ich mit //uhrand markiert und kommentiert
*/
import java.awt.*;
import java.awt.event.*;
import java.io.File;
import javax.swing.*;
import javax.swing.border.BevelBorder;
public class Programm extends JFrame {
// Anfang Variablen
// Ende Variablen
private static final long serialVersionUID = 1L;
private GridBagLayout layout = new GridBagLayout();
private JScrollPane textPane = new JScrollPane();
private JMenuBar barMenu = new JMenuBar();
private JMenu mBFile = new JMenu("Datei");
private JMenuItem mIOpen = new JMenuItem("Öffnen");
private JMenuItem mISave = new JMenuItem("Speichern");
private JMenuItem mISaveAs = new JMenuItem("Speichern als");
private JMenuItem mIExit = new JMenuItem("Beenden");
private JMenu mBEdit = new JMenu("Bearbeiten");
private JMenuItem mIMark = new JMenuItem("Markieren");
private JMenuItem mICopy = new JMenuItem("Kopieren");
private JMenuItem mICut = new JMenuItem("Ausschneiden");
private JMenuItem mIPaste = new JMenuItem("Einfügen");
private JMenu mBHelp = new JMenu("Hilfe");
private JMenuItem mIInfo = new JMenuItem("Info");
private JMenuItem mIHelpsec = new JMenuItem("Hilfe");
private JToolBar barTools = new JToolBar();
private JButton tBSave = new JButton("picS");
private JButton tBOpen = new JButton("picO");
private JButton tBGraphic = new JButton("picG");
private JButton tBBold = new JButton("picB");
private JButton tBItalic = new JButton("picI");
private JButton tBUnderlined = new JButton("picU");
private JComboBox cboFontChooser = new JComboBox();
private JComboBox cboFontSizeChooser = new JComboBox();
private JTextPane textArea = new JTextPane();
private JLabel hitLabel;
private Dimension dimFontSizeChooser = new Dimension();
private Dimension dimFontChooser = new Dimension();
private String[] fonts = {"Serif", "Arial", "SanfSerif", "Monospaced", "Dialog", "DialogInput"};
private String[] fontSizes = {"8","9","10","11","12","13","14","15","16","17","18","19","20","21","22","23","24","25"};
private int deltaX, deltaY;
private JPanel picPanel;//uhrand
private JPanel mainPanel;//uhrand
public Programm(String title) {//uhrand
// Frame-Initialisierung
super(title);
this.addWindowListener(new WindowAdapter() {
@Override
public void windowClosing(WindowEvent evt) { System.exit(0); }
});
this.setLocation(0, 0);
this.setSize(500, 500);
final Container cp = this.getContentPane();
GridBagLayout gbl = new GridBagLayout();
//cp.setLayout(gbl);
// setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //uhrand (überflüssig wegen windowClosing)
this.setExtendedState(MAXIMIZED_BOTH);
mainPanel = new JPanel(gbl);//uhrand
picPanel = new JPanel();//uhrand
picPanel.setLayout(null);
picPanel.setSize(Toolkit.getDefaultToolkit().getScreenSize());
//getContentPane().add(cp, BorderLayout.CENTER);
cp.add(mainPanel, BorderLayout.CENTER);
picPanel.setOpaque(false);
this.getLayeredPane().add(picPanel, JLayeredPane.DRAG_LAYER);
// tBGraphic = new JButton("Bild laden");//uhrand (überflüssig)
// cp.add(tBGraphic, BorderLayout.NORTH);//uhrand (überflüssig)
//this.setVisible(true);
// picPanel.setLocation(mainPanel.getLocation());//uhrand (ist jetzt am Schluss vom Konstruktor)
picPanel.addMouseMotionListener(new MouseMotionAdapter() {//uhrand
@Override
public void mouseDragged(final MouseEvent evt) {
Programm.this.mouseDragged(evt);//uhrand (hier entstand der stackoverflow)
}
});
picPanel.addMouseListener(new MouseAdapter() {//uhrand
@Override
public void mousePressed(final MouseEvent evt) {
Programm.this.mousePressed(evt);//uhrand
}
@Override
public void mouseReleased(final MouseEvent evt) {
Programm.this.mouseReleased(evt);//uhrand
}
});
// Anfang Komponenten
this.setJMenuBar(barMenu);
barMenu.add(mBFile);
barMenu.add(mBEdit);
barMenu.add(mBHelp);
cp.add(barTools, BorderLayout.NORTH);//uhrand
barTools.setFloatable(false);
barTools.setSize(Toolkit.getDefaultToolkit().getScreenSize().width, 30);
mBFile.add(mIOpen);
mIOpen.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
//
}
});
mBFile.add(mISave);
mISave.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
//
}
});
mBFile.add(mISaveAs);
mISaveAs.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
//
}
});
mBFile.add(mIExit);
mIExit.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
//
}
});
mBEdit.add(mIMark);
mIMark.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
//
}
});
mBEdit.add(mICopy);
mICopy.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
//
}
});
mBEdit.add(mICut);
mICut.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
//
}
});
mBEdit.add(mIPaste);
mIPaste.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
//
}
});
mBHelp.add(mIInfo);
mIInfo.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
//
}
});
mBHelp.add(mIHelpsec);
mIHelpsec.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
//
}
});
barTools.add(tBSave);
tBSave.setFocusable(false);
tBSave.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
//
}
});
barTools.add(tBOpen);
tBOpen.setFocusable(false);
tBOpen.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
//
}
});
barTools.add(tBGraphic);
tBGraphic.setFocusable(false);
tBGraphic.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
File picFile = funcOpen("Grafik");
if (picFile != null){
Icon bild = new ImageIcon(picFile.toString());
JLabel label = new JLabel(bild);
label.setBounds(50, 50, bild.getIconWidth(), bild.getIconHeight());
picPanel.add(label);//uhrand
picPanel.repaint();//uhrand
}
}
});
barTools.add(cboFontSizeChooser);
cboFontSizeChooser.setFocusable(false);
dimFontSizeChooser.width = 50;
dimFontSizeChooser.height = 30;
cboFontSizeChooser.setMaximumSize(dimFontSizeChooser);
for (int a = 0; a < fontSizes.length; a++){
cboFontSizeChooser.addItem(fontSizes[a]);
}
cboFontSizeChooser.setSelectedIndex(7);
cboFontSizeChooser.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
//
}
});
barTools.add(cboFontChooser);
cboFontChooser.setFocusable(false);
dimFontChooser.width = 100;
dimFontChooser.height = 30;
cboFontChooser.setMaximumSize(dimFontChooser);
for (int a = 0; a < fonts.length; a++){
cboFontChooser.addItem(fonts[a]);
}
cboFontChooser.setSelectedIndex(1);
cboFontChooser.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
//
}
});
barTools.add(tBBold);
tBBold.setFocusable(false);
tBBold.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
//
}
});
barTools.add(tBItalic);
tBItalic.setFocusable(false);
tBItalic.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
//
}
});
barTools.add(tBUnderlined);
tBUnderlined.setFocusable(false);
tBUnderlined.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
//
}
});
// this.getContentPane().setLayout(layout);//uhrand
textPane.getViewport().add(textArea);
// this.getContentPane().add(barTools, new GridBagConstraints(0, 0, 1, 1, 1.0, 0.0,//uhrand
// GridBagConstraints.NORTH, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0));//uhrand
mainPanel.add(textPane, new GridBagConstraints(0, 1, 1, 1, 1.0, 1.0,//uhrand
GridBagConstraints.NORTH, GridBagConstraints.NONE, new Insets(40, 0, 0, 0), 500, 700));
// Ende Komponenten
this.setResizable(true);
this.setVisible(true);
//wegen der JMenuBar wird der setLocation ein wenig komplizierter: //uhrand
picPanel.setLocation(mainPanel.getLocation().x, mainPanel.getLocation().y+barMenu.getHeight());//uhrand
}
// Anfang Ereignisprozeduren
public void mousePressed(final MouseEvent evt) {
Component c = picPanel.getComponentAt(evt.getPoint());
if (c instanceof JLabel) {
hitLabel = (JLabel) c;
hitLabel.setBorder(new BevelBorder(BevelBorder.RAISED));
deltaX = evt.getX() - hitLabel.getX();
deltaY = evt.getY() - hitLabel.getY();
}
}
public void mouseDragged(final MouseEvent evt) {
if (hitLabel != null) {
int x = evt.getX() - deltaX;
int y = evt.getY() - deltaY;
hitLabel.setLocation(x, y);
picPanel.setComponentZOrder(hitLabel, 0);// JDK 1.5
hitLabel.repaint();//uhrand (verbessert die Performance gegenüber picPanel.repaint)
}
}
public void mouseReleased(final MouseEvent evt) {
if( hitLabel != null ){
hitLabel.setBorder(null);
picPanel.repaint();
hitLabel = null;
}
}
public File funcOpen(String dateiTyp) {
JFileChooser dlgOpen = new JFileChooser();
dlgOpen.setDialogTitle("Öffne " + dateiTyp);
if (dlgOpen.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) {
return dlgOpen.getSelectedFile();
}else{
return null;
}
}
// Ende Ereignisprozeduren
public static void main(String[] args) {
new Programm("");
}
}