001: /*
002: * Copyright (C) 2005 Jeff Tassin
003: *
004: * This library is free software; you can redistribute it and/or
005: * modify it under the terms of the GNU Lesser General Public
006: * License as published by the Free Software Foundation; either
007: * version 2.1 of the License, or (at your option) any later version.
008: *
009: * This library is distributed in the hope that it will be useful,
010: * but WITHOUT ANY WARRANTY; without even the implied warranty of
011: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
012: * Lesser General Public License for more details.
013: *
014: * You should have received a copy of the GNU Lesser General Public
015: * License along with this library; if not, write to the Free Software
016: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
017: */
018:
019: package com.jeta.swingbuilder.gui.components.line;
020:
021: import java.awt.event.ActionEvent;
022: import java.awt.event.ActionListener;
023:
024: import javax.swing.DefaultListModel;
025: import javax.swing.JList;
026:
027: import com.jeta.forms.store.properties.LineProperty;
028: import com.jeta.open.gui.framework.JETAController;
029: import com.jeta.open.gui.framework.JETADialog;
030: import com.jeta.open.gui.utils.JETAToolbox;
031: import com.jeta.open.i18n.I18N;
032:
033: /**
034: *
035: * @author Jeff Tassin
036: */
037: public class CompoundLineController extends JETAController {
038: private CompoundLineView m_view;
039:
040: /**
041: * ctor
042: */
043: public CompoundLineController(CompoundLineView view) {
044: super (view);
045: m_view = view;
046: assignAction(CompoundLineNames.ID_NEW_LINE, new NewLineAction());
047: assignAction(CompoundLineNames.ID_EDIT_LINE,
048: new EditLineAction());
049: assignAction(CompoundLineNames.ID_DELETE_LINE,
050: new DeleteLineAction());
051: assignAction(CompoundLineNames.ID_MOVE_UP, new MoveUpAction());
052: assignAction(CompoundLineNames.ID_MOVE_DOWN,
053: new MoveDownAction());
054: }
055:
056: /**
057: * Edits the given line property
058: */
059: private void editLine(LineProperty lp) {
060: LinePropertiesView view = new LinePropertiesView(lp);
061: JETADialog dlg = (JETADialog) JETAToolbox.createDialog(
062: JETADialog.class, m_view, true);
063: dlg.setPrimaryPanel(view);
064: dlg.setSize(dlg.getPreferredSize());
065: if (lp == null)
066: dlg.setTitle(I18N.getLocalizedMessage("New Line"));
067: else
068: dlg.setTitle(I18N.getLocalizedMessage("Edit Line"));
069:
070: dlg.showCenter();
071: if (dlg.isOk()) {
072: if (lp == null) {
073: m_view.addLine(view.getLineProperty());
074: } else {
075: m_view.setLine(view.getLineProperty(), lp);
076: }
077: }
078: }
079:
080: public class DeleteLineAction implements ActionListener {
081: public void actionPerformed(ActionEvent evt) {
082: m_view.deleteSelectedLine();
083: }
084: }
085:
086: public class EditLineAction implements ActionListener {
087: public void actionPerformed(ActionEvent evt) {
088: LineProperty lp = m_view.getSelectedLine();
089: if (lp != null) {
090: editLine(lp);
091: }
092: }
093: }
094:
095: /**
096: * Moves the current line up
097: */
098: public class MoveUpAction implements ActionListener {
099: public void actionPerformed(ActionEvent evt) {
100: JList list = m_view
101: .getList(CompoundLineNames.ID_LINES_LIST);
102: DefaultListModel model = (DefaultListModel) list.getModel();
103: int index = list.getSelectedIndex();
104: if (index > 0 && model.size() > 1) {
105: Object mv_obj = model.getElementAt(index);
106: Object next_obj = model.getElementAt(index - 1);
107: model.setElementAt(mv_obj, index - 1);
108: model.setElementAt(next_obj, index);
109: list.setSelectedIndex(index - 1);
110: }
111: m_view.ensureIndexIsVisible();
112: }
113: }
114:
115: /**
116: * Moves the current line down
117: */
118: public class MoveDownAction implements ActionListener {
119: public void actionPerformed(ActionEvent evt) {
120: JList list = m_view
121: .getList(CompoundLineNames.ID_LINES_LIST);
122: DefaultListModel model = (DefaultListModel) list.getModel();
123: int index = list.getSelectedIndex();
124: if ((index + 1) < model.size()) {
125: Object mv_obj = model.getElementAt(index);
126: Object next_obj = model.getElementAt(index + 1);
127: model.setElementAt(mv_obj, index + 1);
128: model.setElementAt(next_obj, index);
129: list.setSelectedIndex(index + 1);
130: }
131: m_view.ensureIndexIsVisible();
132: }
133: }
134:
135: /**
136: * Creates a new line
137: */
138: public class NewLineAction implements ActionListener {
139: public void actionPerformed(ActionEvent evt) {
140: editLine(null);
141: }
142: }
143:
144: }
|