From: <aki...@us...> - 2006-12-22 22:00:31
|
Revision: 1216 http://svn.sourceforge.net/gridarta/?rev=1216&view=rev Author: akirschbaum Date: 2006-12-22 14:00:27 -0800 (Fri, 22 Dec 2006) Log Message: ----------- Use ActionFactor to create toolbar. Modified Paths: -------------- trunk/crossfire/src/cfeditor/CMainView.java trunk/crossfire/src/cfeditor/action.properties trunk/crossfire/src/cfeditor/messages.properties trunk/crossfire/src/cfeditor/messages_de.properties Added Paths: ----------- trunk/crossfire/resource/icons/navigation/ trunk/crossfire/resource/icons/navigation/Back16.gif trunk/crossfire/resource/icons/navigation/Forward16.gif Removed Paths: ------------- trunk/crossfire/src/cfeditor/CMainToolbar.java Added: trunk/crossfire/resource/icons/navigation/Back16.gif =================================================================== (Binary files differ) Property changes on: trunk/crossfire/resource/icons/navigation/Back16.gif ___________________________________________________________________ Name: svn:mime-type + application/octet-stream Added: trunk/crossfire/resource/icons/navigation/Forward16.gif =================================================================== (Binary files differ) Property changes on: trunk/crossfire/resource/icons/navigation/Forward16.gif ___________________________________________________________________ Name: svn:mime-type + application/octet-stream Deleted: trunk/crossfire/src/cfeditor/CMainToolbar.java =================================================================== --- trunk/crossfire/src/cfeditor/CMainToolbar.java 2006-12-22 21:32:21 UTC (rev 1215) +++ trunk/crossfire/src/cfeditor/CMainToolbar.java 2006-12-22 22:00:27 UTC (rev 1216) @@ -1,341 +0,0 @@ -/* - * Crossfire Java Editor. - * Copyright (C) 2000 Michael Toennies - * Copyright (C) 2001 Andreas Vogl - * - * (code based on: Gridder. 2D grid based level editor. (C) 2000 Pasi Keränen) - * - * 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 2 of the - * License, or (at your option) any later version. - * - * 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, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA - * 02111-1307, USA. - * - */ - -package cfeditor; - -import java.awt.Dimension; -import java.awt.Insets; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; -import java.awt.event.InputEvent; -import java.awt.event.MouseAdapter; -import java.awt.event.MouseEvent; -import java.util.Enumeration; -import java.util.Vector; -import javax.swing.ButtonGroup; -import javax.swing.JButton; -import javax.swing.JPopupMenu; -import javax.swing.JRadioButtonMenuItem; -import javax.swing.JToolBar; -import javax.swing.SwingConstants; -import org.jetbrains.annotations.Nullable; - -/** - * <code>CMainTolbar</code> implements the main toolbar of the application. - * @author <a href="mailto:mic...@no...">Michael Toennies</a> - * @author <a href="mailto:and...@gm...">Andreas Vogl</a> - */ -public final class CMainToolbar extends JToolBar { - - /** The key used to store the icons/labels setting to the INI file. */ - public static final String SHOW_ICONS_AND_LABELS_KEY = "MainToolbar.iconsAndLabels"; - - /** Enumerated icons/labels mode. Shows both icons and labels. */ - public static final int SHOW_ICONS_AND_LABELS = 0; - - /** Enumerated icons/labels mode. Shows only icons. */ - public static final int SHOW_ICONS_ONLY = 1; - - /** Enumerated icons/labels mode. Shows only labels. */ - public static final int SHOW_LABELS_ONLY = 2; - - /** The controller of this toolbar view. */ - private final CMainControl mainControl; - - /** The current icon/labels mode. */ - private int eIconAndLabelVisibility = SHOW_ICONS_ONLY; - - /** The popup menu. */ - private final CPopupMenu popupMenu; - - private JButton save; - - private JButton saveAs; - - private static final long serialVersionUID = 1L; - - /** - * Constructs a new toolbar. - * @param mainControl The controller of this toolbar. - */ - CMainToolbar(final CMainControl mainControl) { - super(SwingConstants.VERTICAL); // construct with vertical alignment - this.mainControl = mainControl; - - eIconAndLabelVisibility = Integer.parseInt(CSettings.getInstance(IGUIConstants.APP_NAME).getProperty(SHOW_ICONS_AND_LABELS_KEY, "" + SHOW_ICONS_ONLY)); - popupMenu = new CPopupMenu(); - addMouseListener( - new MouseAdapter() { - @Override public void mousePressed(final MouseEvent event) { - if ((event.getModifiers() & InputEvent.META_MASK) != 0) { - popupMenu.show(CMainToolbar.this, event.getX(), event.getY()); - } - } - }); - - rebuild(); - } - - /** - * Returns the text if it should be visible, otherwise <code>null</code>. - * @param label The label text. - * @return The label text or null if labels should not be visible. - */ - @Nullable private String filterLabel(final String label) { - return eIconAndLabelVisibility == SHOW_ICONS_ONLY ? null : label; - } - - /** - * Returns the icon name if it should be visible, otherwise <code>null</code>. - * @param iconName The icon name. - * @return The icon name or null if icons should not be visible. - */ - @Nullable private String filterIconName(final String iconName) { - return eIconAndLabelVisibility == SHOW_LABELS_ONLY ? null : iconName; - } - - /** - * Rebuilds the toolbar by first removing the buttons and - * then adding them again. - */ - private void rebuild() { - removeAll(); - - setMargin(new Insets(IGUIConstants.DIALOG_INSETS, 0, IGUIConstants.DIALOG_INSETS, IGUIConstants.DIALOG_INSETS)); - - final Vector<JButton> buttons = new Vector<JButton>(10, 2); - final JButton newButton = new CFancyButton( - filterLabel("New"), - "New Map", - filterIconName(IGUIConstants.NEW_LEVEL_ICON), - new ActionListener() { - public void actionPerformed(final ActionEvent event) { - mainControl.createNew(); - } - }); - newButton.setVerticalTextPosition(SwingConstants.BOTTOM); - newButton.setHorizontalTextPosition(SwingConstants.CENTER); - buttons.addElement(newButton); - add(newButton); - - final JButton open = new CFancyButton( - filterLabel("Open"), - "Open Map File", - filterIconName(IGUIConstants.OPEN_LEVEL_ICON), - new ActionListener() { - public void actionPerformed(final ActionEvent event) { - mainControl.open(); - } - }); - open.setVerticalTextPosition(SwingConstants.BOTTOM); - open.setHorizontalTextPosition(SwingConstants.CENTER); - buttons.addElement(open); - add(open); - - save = new CFancyButton( - filterLabel("Save"), - "Save Map File", - filterIconName(IGUIConstants.SAVE_LEVEL_ICON), - new ActionListener() { - public void actionPerformed(final ActionEvent event) { - mainControl.save(); - } - }); - save.setVerticalTextPosition(SwingConstants.BOTTOM); - save.setHorizontalTextPosition(SwingConstants.CENTER); - buttons.addElement(save); - add(save); - - saveAs = new CFancyButton( - filterLabel("Save As"), - "Save Map File As", - filterIconName(IGUIConstants.SAVE_LEVEL_AS_ICON), - new ActionListener() { - public void actionPerformed(final ActionEvent event) { - mainControl.saveAs(); - } - }); - saveAs.setVerticalTextPosition(SwingConstants.BOTTOM); - saveAs.setHorizontalTextPosition(SwingConstants.CENTER); - buttons.addElement(saveAs); - add(saveAs); - - addSeparator(); - - final JButton prevWindow = new CFancyButton( - filterLabel("Prev"), - "Show Previous Window", - filterIconName(IGUIConstants.PREVIOUS_WINDOW_ICON), - new ActionListener() { - public void actionPerformed(final ActionEvent event) { - mainControl.prevWindow(); - } - }); - prevWindow.setVerticalTextPosition(SwingConstants.BOTTOM); - prevWindow.setHorizontalTextPosition(SwingConstants.CENTER); - buttons.addElement(prevWindow); - add(prevWindow); - - final JButton nextWindow = new CFancyButton( - filterLabel("Next"), - "Show Next Window", - filterIconName(IGUIConstants.NEXT_WINDOW_ICON), - new ActionListener() { - public void actionPerformed(final ActionEvent event) { - mainControl.nextWindow(); - } - }); - nextWindow.setVerticalTextPosition(SwingConstants.BOTTOM); - nextWindow.setHorizontalTextPosition(SwingConstants.CENTER); - buttons.addElement(nextWindow); - add(nextWindow); - - doLayout(); - - // If icons and labels are visible make buttons square shaped - if (eIconAndLabelVisibility == SHOW_ICONS_AND_LABELS) { - int maxWidth = 16; - for (Enumeration<JButton> enu = buttons.elements(); - enu.hasMoreElements();) { - final JButton button = enu.nextElement(); - maxWidth = Math.max(maxWidth, button.getWidth()); - } - - for (final Enumeration<JButton> enu = buttons.elements(); enu.hasMoreElements();) { - final JButton button = enu.nextElement(); - final Dimension size = new Dimension(maxWidth, maxWidth); - button.setSize(size); - button.setMinimumSize(size); - button.setMaximumSize(size); - button.setPreferredSize(size); - } - } - - refresh(); - doLayout(); - repaint(); - mainControl.refreshMainView(); - } - - /** - * Sets the icon and label visibility. - * @param eVisibility One of the enumerated SHOW_xxx values. - */ - void setIconAndLabelVisibility(final int eVisibility) { - switch (eVisibility) { - case SHOW_ICONS_AND_LABELS: - case SHOW_ICONS_ONLY: - case SHOW_LABELS_ONLY: - eIconAndLabelVisibility = eVisibility; - CSettings.getInstance(IGUIConstants.APP_NAME).setProperty(SHOW_ICONS_AND_LABELS_KEY, "" + eVisibility); - break; - - default: - return; - } - - rebuild(); - } - - /** Refreshes the state of items in this toolbar. */ - void refresh() { - final boolean fLevelEdited = mainControl.isLevelEdited(); - save.setEnabled(mainControl.isPlainSaveEnabled()); - saveAs.setEnabled(fLevelEdited); - } - - /** - * The popup menu that is shown on right click - * upon this toolbar. - */ - public final class CPopupMenu extends JPopupMenu { - - final JRadioButtonMenuItem iconsAndLabels; - - final JRadioButtonMenuItem iconsOnly; - - final JRadioButtonMenuItem labelsOnly; - - final ButtonGroup group; - - private static final long serialVersionUID = 1L; - - /** Constructs the popup menu with the appropriate menuitems. */ - public CPopupMenu() { - group = new ButtonGroup(); - iconsAndLabels = new JRadioButtonMenuItem("Icons&Labels"); - iconsAndLabels.addActionListener( - new ActionListener() { - public void actionPerformed(final ActionEvent event) { - setIconAndLabelVisibility(SHOW_ICONS_AND_LABELS); - } - }); - group.add(iconsAndLabels); - add(iconsAndLabels); - iconsOnly = new JRadioButtonMenuItem("Icons"); - iconsOnly.addActionListener( - new ActionListener() { - public void actionPerformed(final ActionEvent event) { - setIconAndLabelVisibility(SHOW_ICONS_ONLY); - } - }); - group.add(iconsOnly); - add(iconsOnly); - labelsOnly = new JRadioButtonMenuItem("Labels"); - labelsOnly.addActionListener( - new ActionListener() { - public void actionPerformed(final ActionEvent event) { - setIconAndLabelVisibility(SHOW_LABELS_ONLY); - } - }); - group.add(labelsOnly); - add(labelsOnly); - - refresh(); - } - - /** Refreshes the states of the menuitems. */ - void refresh() { - switch (eIconAndLabelVisibility) { - case SHOW_ICONS_AND_LABELS: - group.setSelected(iconsAndLabels.getModel(), true); - group.setSelected(iconsOnly.getModel(), false); - group.setSelected(labelsOnly.getModel(), false); - break; - - case SHOW_ICONS_ONLY: - group.setSelected(iconsAndLabels.getModel(), false); - group.setSelected(iconsOnly.getModel(), true); - group.setSelected(labelsOnly.getModel(), false); - break; - - case SHOW_LABELS_ONLY: - group.setSelected(iconsAndLabels.getModel(), false); - group.setSelected(iconsOnly.getModel(), false); - group.setSelected(labelsOnly.getModel(), true); - break; - } - } - } -} Modified: trunk/crossfire/src/cfeditor/CMainView.java =================================================================== --- trunk/crossfire/src/cfeditor/CMainView.java 2006-12-22 21:32:21 UTC (rev 1215) +++ trunk/crossfire/src/cfeditor/CMainView.java 2006-12-22 22:00:27 UTC (rev 1216) @@ -117,9 +117,6 @@ /** The controller of this view. */ private static final CMainControl mainControl = CMainControl.getInstance(); - /** The main toolbar. */ - private CMainToolbar toolBar; - /** The main statusbar. */ private CMainStatusbar statusBar; @@ -276,9 +273,7 @@ mainControl.getFilterControl().createMenuEntries(menuAnalyze); } - toolBar = new CMainToolbar(mainControl); - //getContentPane().add(toolBar, BorderLayout.NORTH); - getContentPane().add(toolBar, BorderLayout.WEST); // put it left + add(ACTION_FACTORY.createToolBar("main"), BorderLayout.NORTH); // set bounds (location and size) of the main frame setBounds(x, y, width, height); @@ -473,7 +468,6 @@ archPanel.refresh(); mapTileList.refresh(); mapArchPanel.refresh(); - toolBar.refresh(); statusBar.refresh(); refresh3(); @@ -828,7 +822,7 @@ private final String[] directionsMap = {"enterNorthMap", "enterEastMap", "enterSouthMap", "enterWestMap", "enterUpperMap", "enterLowerMap"}; private void initActions() { - ACTION_FACTORY.createActions(true, mainControl, "createNew", "open", "options", "exit", "gc", "onlineHelp", "about"); + ACTION_FACTORY.createActions(true, mainControl, "createNew", "open", "options", "exit", "gc", "prevWindow", "nextWindow", "onlineHelp", "about"); ACTION_FACTORY.createActions(true, mainControl.getScriptController().getView(), "editPlugins", "savePlugins", "exportPluginAs", "importPlugin"); ACTION_FACTORY.createActions(true, mainControl, directionsMap); ACTION_FACTORY.createActions(true, this, "resetView"); Modified: trunk/crossfire/src/cfeditor/action.properties =================================================================== --- trunk/crossfire/src/cfeditor/action.properties 2006-12-22 21:32:21 UTC (rev 1215) +++ trunk/crossfire/src/cfeditor/action.properties 2006-12-22 22:00:27 UTC (rev 1216) @@ -30,6 +30,10 @@ mapwindowCursor.menu=moveCursor - selectTile startStopDrag addToSelection subFromSelection releaseDrag - insertArch deleteArch - selectArchAbove selectArchBelow - archAttributes mapwindowView.menu=showMonster showExit showBackground showDoor showWall showEquipment showTreasure showConnected resetView +########## +# ToolBars +main.toolbar=createNew open save saveAs - prevWindow nextWindow + ####### # File @@ -108,6 +112,11 @@ importPlugin.icon=ImportPluginSmallIcon +nextWindow.icon=navigation/Forward16 + +prevWindow.icon=navigation/Back16 + + onlineHelp.icon=general/Help16 about.icon=general/About16 Modified: trunk/crossfire/src/cfeditor/messages.properties =================================================================== --- trunk/crossfire/src/cfeditor/messages.properties 2006-12-22 21:32:21 UTC (rev 1215) +++ trunk/crossfire/src/cfeditor/messages.properties 2006-12-22 22:00:27 UTC (rev 1216) @@ -406,6 +406,14 @@ window.text=Window window.mnemonic=W +nextWindow.text=Next Window +nextWindow.shortdescription=Display next window +nextWindow.accel=shift pressed PAGE_UP + +prevWindow.text=Previous Window +prevWindow.shortdescription=Display previous window +prevWindow.accel=shift pressed PAGE_DOWN + closeAll.text=Close All closeAll.shortdescription=Close all maps closeAll.longdescription=Closes all opened maps Modified: trunk/crossfire/src/cfeditor/messages_de.properties =================================================================== --- trunk/crossfire/src/cfeditor/messages_de.properties 2006-12-22 21:32:21 UTC (rev 1215) +++ trunk/crossfire/src/cfeditor/messages_de.properties 2006-12-22 22:00:27 UTC (rev 1216) @@ -630,6 +630,14 @@ window.text=Fenster window.mnemonic=F +nextWindow.text=N\xE4chstes Fenster +nextWindow.shortdescription=Zeige das n\xE4chste Fenster +nextWindow.accel=shift pressed PAGE_UP + +prevWindow.text=Vorheriges Fenster +prevWindow.shortdescription=Zeige das vorherige Fenster +prevWindow.accel=shift pressed PAGE_DOWN + closeAll.text=Alle schlie\xDFen closeAll.shortdescription=Alle Karten schlie\xDFen closeAll.longdescription=Schlie\xDFt alle ge\xF6ffneten Karten. This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |