From 4b8e9a0a15b2dc3d94ea3cfc4297533b1e35d7d8 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Bj=C3=B6rn=20Lanneskog?= Date: Sat, 10 May 2003 12:20:49 +0000 Subject: [PATCH] =?utf8?q?vars=E5=20god=20einar?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- MooMenu.java | 54 ++++++++++++++++--- MooToolbar.java | 137 +++++++++++++++++++++++++++++++----------------- 2 files changed, 135 insertions(+), 56 deletions(-) diff --git a/MooMenu.java b/MooMenu.java index ca367b3..eeb1b21 100644 --- a/MooMenu.java +++ b/MooMenu.java @@ -3,6 +3,11 @@ import javax.swing.filechooser.*; import java.awt.event.*; import java.io.*; +/** + * Moosiques GUI representing a menubar, menus and menuitems + * + * @author Björn Lanneskog + */ public class MooMenu extends JMenuBar implements ActionListener { /* @@ -30,9 +35,11 @@ Music Insert Measure... Lagt till Kanske också: Reset Solo / Mute */ - private JMenu file, edit, playback, track, help, music; + /** + * contructs a menubar + */ public MooMenu() { file = makeMenu("File", KeyEvent.VK_F); add(file); @@ -87,19 +94,38 @@ Kanske ocks help.add(makeItem(help, "About")); } + /** + * creates a menu for the menubar + * @param name the name of the menu + * @param mnemonic the shortcut to activate the menu + * @return menu the menu to be added to the menubar + */ private JMenu makeMenu(String name, int mnemonic) { JMenu menu = new JMenu(name); menu.setMnemonic(mnemonic); return menu; } - + + /** + * creates a menuitem + * @param menu the menu to which the item is being added to + * @param name the name of this menuitem + * @return item the item to add to the menu + */ private JMenuItem makeItem(JMenu menu, String name) { JMenuItem item = new JMenuItem(name); item.addActionListener(this); menu.add(item); return item; } - + + /** + * creates a menuitem + * @param menu the menu to which the item is being added to + * @param name the name of this menuitem + * @param key the shortcut to activate the command + * @return item the item to add to the menu + */ private JMenuItem makeItem(JMenu menu, String name, int key) { JMenuItem item = new JMenuItem(name); item.setAccelerator(KeyStroke.getKeyStroke(key, ActionEvent.CTRL_MASK)); @@ -108,6 +134,11 @@ Kanske ocks return item; } + /** + * checks if the fileformat is compatible with our program + * @param f the file to check + * @return true or false + */ private boolean isMidiFile(File f) { if(f != null) { String extension = f.getName().substring(f.getName().lastIndexOf('.') + 1).toLowerCase().trim(); @@ -152,10 +183,13 @@ Kanske ocks } else if (command == "Preferences") { - } else if (command == "Play") { - Moosique.play(); + } else if (command == "Play / Resume") { + //if (Moosique.getSequence().isRunning()) { + //Moosique.pause(); + //} else Moosique.play(); + } else if (command == "Pause") { - // Koda för resume också + // koda för resume också Moosique.pause(); } else if (command == "Stop") { Moosique.stop(); @@ -194,7 +228,7 @@ Kanske ocks JOptionPane.showMessageDialog(null, "här kommer about att komma"); } } - + class MidiFileFilter extends javax.swing.filechooser.FileFilter { public boolean accept(File f) { if(f != null) { @@ -203,8 +237,12 @@ Kanske ocks return false; } + /* + * gets the description of the filetype + * @return "Midifiles the only filetyp compatibel with the program + */ public String getDescription() { return "MIDI files"; } } -} \ No newline at end of file +} diff --git a/MooToolbar.java b/MooToolbar.java index 84f0c53..542488c 100644 --- a/MooToolbar.java +++ b/MooToolbar.java @@ -1,15 +1,30 @@ import javax.swing.*; import java.awt.event.*; import java.awt.*; +import javax.sound.midi.*; +import javax.swing.Icon; +/** + * Moosiques GUI representing a toolbar, with the most frequently used commands. + * + * @author Björn Lanneskog + */ public class MooToolbar extends JToolBar implements ActionListener { + private JButton rewind, playpause, stop, fastforward; + private JLabel measure, beats, ticks, measurevalue, beatsvalue, ticksvalue; + private Image pauseimage, playimage; + + /** + * Constructs a toolbar + */ + public MooToolbar() { rewind = createButton("images/rewind.gif", "rewind"); add(rewind); - playpause = createButton("images/play.gif", "play"); + playpause = createButton("images/play.gif", "play/pause"); add(playpause); stop = createButton("images/stop.gif", "stop"); @@ -18,64 +33,90 @@ public class MooToolbar extends JToolBar implements ActionListener { fastforward = createButton("images/forward.gif", "fast forward"); add(fastforward); - meas = createProjIndLabel("Mrs"); - beat = createProjIndLabel("Beat"); - tick = createProjIndLabel("Tick"); - - measvalue = createProjIndLabel("1"); - beatvalue = createProjIndLabel("1"); - ticksvalue = createProjIndLabel("1"); - - JPanel measbeattick = new JPanel(); - measbeattick.setMaximumSize(new Dimension(80,40)); - measbeattick.setLayout(new GridLayout(2,3)); - measbeattick.add(meas); - measbeattick.add(beat); - measbeattick.add(tick); - measbeattick.add(measvalue); - measbeattick.add(beatvalue); - measbeattick.add(ticksvalue); - - add(measbeattick); + JPanel panel = new JPanel(); + panel.setMaximumSize(new Dimension(100,22)); + panel.setLayout(new GridLayout(2,4)); + add(panel); + + panel.add(new JPanel()); + + measure = createProjIndLabel("Mrs",10); + panel.add(measure); + + beats = createProjIndLabel("Beat",10); + panel.add(beats); + + ticks = createProjIndLabel("Tick",10); + panel.add(ticks); + + panel.add(new JPanel()); + + measurevalue = createProjIndLabel("1",10); + panel.add(measurevalue); + + beatsvalue = createProjIndLabel("1",10); + panel.add(beatsvalue); + + ticksvalue = createProjIndLabel("1",10); + panel.add(ticksvalue); + + playimage = Toolkit.getDefaultToolkit().getImage("images/play.gif"); + pauseimage = Toolkit.getDefaultToolkit().getImage("images/pause.gif"); + } - private JButton createButton(String imageLocation, String toolTip) { - JButton button = new JButton (new ImageIcon(imageLocation)); - button.setToolTipText(toolTip); + /** + * creates a JButton for the toolbar + * @param imagelocation the imagelacation of the the image displayed in the button + * @param tooltip the tooltip associated with this button + * @return button the button to be attached to the toolbar + */ + private JButton createButton(String imagelocation, String tooltip) { + JButton button = new JButton (new ImageIcon(imagelocation)); + button.setToolTipText(tooltip); button.addActionListener(this); return button; } - - private JLabel createProjIndLabel(String title){ - JLabel titelvalue = new JLabel(title, JLabel.CENTER); - titelvalue.setFont(new Font("Times New Roman", Font.PLAIN ,8)); - titelvalue.setHorizontalTextPosition(JLabel.CENTER); + /** + * creates JLabels for the progressindikator, attached to the toolbar + * @param title the titel displayed on the label + * @param fontsize the fontzise of the text displayed on the label + * @param titelvalue the label that is a part of the progressindikator + */ + private JLabel createProjIndLabel(String title, int fontsize){ + JLabel titelvalue = new JLabel(title,JLabel.CENTER); + titelvalue.setFont(new Font("Times New Roman", + Font.PLAIN ,fontsize)); return titelvalue; } + // int pos = Moosique.getSequencer().getTickPosition(); + // int measures = pos / (4 * Moosique.getSequence.get) + // int beats = (pos - measures * 4 * 96) / 96; + // int ticks = (pos - measures*4*96 - beats*96); + - public void actionPerformed(ActionEvent e) {} - - /*if () { - - } else if () { - - - } else if () { + public void actionPerformed(ActionEvent e) { + + if (((JButton)e.getSource()).getToolTipText() == "rewind") { + //få in rewindmetoden + } else if (((JButton)e.getSource()).getToolTipText() == "play/pause") { + if (Moosique.getSequence().isRunning()) { + Moosique.pause(); + playpause.getIcon().setImage(playimage); + } else { + Moosique.play(); + playpause.getIcon().setImage(pauseimage); + } - } else if () { + } else if (((JButton)e.getSource()).getToolTipText() == "stop") { + Moosique.stop(); + + } else if (((JButton)e.getSource()).getToolTipText() == "fastforward") { + // få in fastforwardmetoden - }*/ - private JButton rewind; - private JButton playpause; - private JButton stop; - private JButton fastforward; - private JLabel meas; - private JLabel beat; - private JLabel tick; - private JLabel measvalue; - private JLabel beatvalue; - private JLabel ticksvalue; + } + } } -- 2.39.2