001: /*
002: * ImageMode.java
003: *
004: * Copyright (C) 2000-2002 Peter Graves
005: * $Id: ImageMode.java,v 1.1.1.1 2002/09/24 16:08:07 piso Exp $
006: *
007: * This program is free software; you can redistribute it and/or
008: * modify it under the terms of the GNU General Public License
009: * as published by the Free Software Foundation; either version 2
010: * of the License, or (at your option) any later version.
011: *
012: * This program is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of
014: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
015: * GNU General Public License for more details.
016: *
017: * You should have received a copy of the GNU General Public License
018: * along with this program; if not, write to the Free Software
019: * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
020: */
021:
022: package org.armedbear.j;
023:
024: import java.awt.Color;
025:
026: public final class ImageMode extends AbstractMode implements Constants,
027: Mode {
028: private static final String MENU_NAME = "ImageMode";
029: private static final ImageMode mode = new ImageMode();
030:
031: private ImageMode() {
032: super (IMAGE_MODE, IMAGE_MODE_NAME);
033: setProperty(Property.VERTICAL_RULE, 0);
034: }
035:
036: public static final ImageMode getMode() {
037: return mode;
038: }
039:
040: protected void setKeyMapDefaults(KeyMap km) {
041: km.mapKey('c', "imageCycleBackground");
042: km.mapKey('f', "imageFit");
043: km.mapKey('r', "imageRestore");
044: km.mapKey('=', "imageZoomIn");
045: km.mapKey('-', "imageZoomOut");
046: }
047:
048: public String getMenuName() {
049: return MENU_NAME;
050: }
051:
052: public MenuBar createMenuBar(Frame frame) {
053: MenuBar menuBar = new MenuBar(MENU_NAME);
054: menuBar.add(new Menu("File", 'F'));
055: menuBar.add(new Menu("View", 'V'));
056: menuBar.add(new Menu("Image", 'I'));
057: menuBar.add(new Menu("Help", 'H'));
058: return menuBar;
059: }
060:
061: public void populateMenu(Editor editor, Menu menu) {
062: final String text = menu.getText();
063: if (text == "File") {
064: menu.add(editor, "New", 'N', "newBuffer");
065: menu.add(editor, "Open...", 'O', "openFile");
066: menu.add(editor, "Save All", 'A', "saveAll");
067: menu.add(editor, "Close", 'C', "killBuffer");
068: menu.add(editor, "Close All", 'L', "closeAll");
069: menu.add(editor, "Close Others", 'H', "closeOthers");
070: menu.add(editor, "Reload", 'R', "revertBuffer");
071: menu.addSeparator();
072: menu.add(editor, "Next Buffer", 'T', "nextBuffer");
073: menu.add(editor, "Previous Buffer", 'R', "prevBuffer");
074: menu.addSeparator();
075: menu.add(editor, "New Frame", 'M', "newFrame");
076: menu.add(editor, "Execute Command...", 'D',
077: "executeCommand");
078: menu.addSeparator();
079: menu.add(editor, "Save All/Exit", '/', "saveAllExit");
080: menu.add(editor, "Exit", 'X', "quit");
081: } else if (text == "Image") {
082: menu.add(editor, "Zoom In", 'I', "imageZoomIn");
083: menu.add(editor, "Zoom Out", 'O', "imageZoomOut");
084: menu.add(editor, "Scale to Fit Display", 'F', "imageFit");
085: menu.add(editor, "Restore Original Size", 'R',
086: "imageRestore");
087: menu.add(editor, "Change Background Color", 'C',
088: "imageCycleBackground");
089: } else
090: super .populateMenu(editor, menu);
091: }
092:
093: public Formatter getFormatter(Buffer buffer) {
094: return null;
095: }
096:
097: public static void imageCycleBackground() {
098: final Buffer buffer = Editor.currentEditor().getBuffer();
099: if (buffer instanceof ImageBuffer) {
100: ((ImageBuffer) buffer).cycleBackground();
101: for (EditorIterator it = new EditorIterator(); it.hasNext();) {
102: Editor ed = it.nextEditor();
103: if (ed.getBuffer() == buffer)
104: ed.getDisplay().repaint();
105: }
106: }
107: }
108:
109: public static void imageZoomIn() {
110: final Buffer buffer = Editor.currentEditor().getBuffer();
111: if (buffer instanceof ImageBuffer)
112: ((ImageBuffer) buffer).zoomIn();
113: }
114:
115: public static void imageZoomOut() {
116: final Buffer buffer = Editor.currentEditor().getBuffer();
117: if (buffer instanceof ImageBuffer)
118: ((ImageBuffer) buffer).zoomOut();
119: }
120:
121: public static void imageFit() {
122: final Buffer buffer = Editor.currentEditor().getBuffer();
123: if (buffer instanceof ImageBuffer)
124: ((ImageBuffer) buffer).fit();
125: }
126:
127: public static void imageRestore() {
128: final Buffer buffer = Editor.currentEditor().getBuffer();
129: if (buffer instanceof ImageBuffer)
130: ((ImageBuffer) buffer).restore();
131: }
132: }
|