001: /*
002: * (C) Copyright SimulacraMedia 2003. All rights reserved.
003: *
004: * Created on 23-Nov-2003
005: *
006: */
007: package org.openharmonise.him.displaycomponents.table.title;
008:
009: import java.awt.Color;
010: import java.awt.Dimension;
011: import java.awt.FlowLayout;
012: import java.awt.Font;
013: import java.awt.LayoutManager;
014: import java.awt.event.ActionEvent;
015: import java.awt.event.ActionListener;
016:
017: import javax.swing.ImageIcon;
018: import javax.swing.JButton;
019: import javax.swing.JComboBox;
020: import javax.swing.JFrame;
021: import javax.swing.JLabel;
022: import javax.swing.JPanel;
023:
024: import org.openharmonise.him.configuration.ConfigStore;
025: import org.openharmonise.him.displaycomponents.table.TableView;
026: import org.openharmonise.him.displaycomponents.table.order.OrderDialog;
027: import org.openharmonise.him.harmonise.HarmonisePaths;
028: import org.openharmonise.swing.FontManager;
029: import org.openharmonise.vfs.VirtualFile;
030: import org.openharmonise.vfs.context.ContextEvent;
031: import org.openharmonise.vfs.context.ContextHandler;
032: import org.openharmonise.vfs.context.ContextListener;
033: import org.openharmonise.vfs.context.ContextType;
034: import org.openharmonise.vfs.gui.IconManager;
035:
036: /**
037: * The title bar for the table view.
038: *
039: * @author Matthew Large
040: * @version $Revision: 1.2 $
041: *
042: */
043: public class TitleBar extends JPanel implements ActionListener,
044: ContextListener {
045:
046: /**
047: * Table view.
048: */
049: private TableView m_table = null;
050:
051: /**
052: * Selected highlight colour.
053: */
054: private Color m_selectedColor = new Color(173, 169, 143);
055:
056: /**
057: * Label for the title.
058: */
059: private JLabel m_title = new JLabel();
060:
061: /**
062: * Display name of collection.
063: */
064: private String m_sDisplayName = "";
065:
066: /**
067: * File name of collection.
068: */
069: private String m_sFileName = "";
070:
071: /**
072: * Order type selector.
073: */
074: private JComboBox m_orderChooser = new JComboBox(new String[] {
075: "View by name", "View by date", "View by default order" });
076:
077: /**
078: * Set default order button.
079: */
080: private JButton m_OrderServerButton = new JButton(
081: "Set Default order");
082:
083: /**
084: * Resource name display type selector.
085: */
086: private JComboBox m_displayChooser = new JComboBox(new String[] {
087: "Display resource filename", "Display resource title",
088: "Display resource harmonise id" });
089:
090: /**
091: *
092: */
093: public TitleBar() {
094: super ();
095: this .setup();
096: }
097:
098: /**
099: * Confiures the title bar.
100: *
101: */
102: private void setup() {
103: FlowLayout fl = new FlowLayout(FlowLayout.LEFT);
104: fl.setVgap(3);
105: fl.setHgap(10);
106: this .setLayout(fl);
107:
108: // String fontName = "Dialog";
109: // int fontSize = 13;
110: // Font font = new Font(fontName, Font.PLAIN, 11);
111: // Font boldFont = new Font(fontName, Font.BOLD, fontSize);
112:
113: this .m_title.setFont(FontManager.getInstance().getFont(
114: FontManager.FONT_RESOURCE_TITLE_BOLD));
115: this .m_title.setPreferredSize(new Dimension(180, 20));
116: this .add(this .m_title);
117:
118: this .m_orderChooser.addActionListener(this );
119: this .m_orderChooser.setFont(FontManager.getInstance().getFont(
120: FontManager.FONT_STANDARD));
121: this .m_orderChooser.setActionCommand("ORDER_CHOOSER");
122: this .m_orderChooser.setPreferredSize(new Dimension(150, 20));
123: this .m_orderChooser.setVisible(false);
124: this .add(this .m_orderChooser);
125:
126: this .m_OrderServerButton.setFont(FontManager.getInstance()
127: .getFont(FontManager.FONT_STANDARD));
128: this .m_OrderServerButton
129: .setPreferredSize(new Dimension(120, 20));
130: this .m_OrderServerButton.setVisible(false);
131: this .m_OrderServerButton.setActionCommand("ORDER");
132: this .m_OrderServerButton.addActionListener(this );
133: this .m_OrderServerButton
134: .setToolTipText("Set the default order for the current collection");
135: this .add(this .m_OrderServerButton);
136:
137: this .m_displayChooser.addActionListener(this );
138: this .m_displayChooser.setFont(FontManager.getInstance()
139: .getFont(FontManager.FONT_STANDARD));
140: this .m_displayChooser.setActionCommand("DISPLAY_CHOOSER");
141: this .m_displayChooser.setPreferredSize(new Dimension(150, 20));
142: this .m_displayChooser.setVisible(false);
143: this .add(this .m_displayChooser);
144: String sValue = ConfigStore.getInstance().getPropertyValue(
145: "FILENAME_DISPLAY");
146: if (sValue != null && sValue.length() > 0
147: && sValue.equals("FILENAME")) {
148: this .m_displayChooser
149: .setSelectedItem("Display resource filename");
150: } else if (sValue != null && sValue.length() > 0
151: && sValue.equals("ID")) {
152: this .m_displayChooser
153: .setSelectedItem("Display resource harmonise id");
154: } else {
155: this .m_displayChooser
156: .setSelectedItem("Display resource title");
157: }
158:
159: ContextHandler.getInstance().addListener(
160: ContextType.CONTEXT_DIRS, this );
161: ContextHandler.getInstance().addListener(
162: ContextType.CONTEXT_TABS, this );
163: ContextHandler.getInstance().addListener(
164: ContextType.CONTEXT_FILENAME_DISPLAY, this );
165: }
166:
167: /**
168: * Sets the title.
169: *
170: * @param sTitle Title
171: */
172: public void setTitle(String sTitle) {
173: this .m_title.setText(sTitle);
174: }
175:
176: /**
177: * @param arg0
178: */
179: private TitleBar(boolean arg0) {
180: super (arg0);
181: }
182:
183: /**
184: * @param arg0
185: */
186: private TitleBar(LayoutManager arg0) {
187: super (arg0);
188: }
189:
190: /**
191: * @param arg0
192: * @param arg1
193: */
194: private TitleBar(LayoutManager arg0, boolean arg1) {
195: super (arg0, arg1);
196: }
197:
198: /* (non-Javadoc)
199: * @see com.simulacramedia.contentmanager.context.ContextListener#contextMessage(com.simulacramedia.contentmanager.context.ContextEvent)
200: */
201: public void contextMessage(ContextEvent ce) {
202: if (ce.CONTEXT_TYPE == ContextType.CONTEXT_DIRS) {
203: VirtualFile vfDir = ce.getVFS()
204: .getVirtualFile(ce.getPath()).getResource();
205: m_sDisplayName = vfDir.getVFS().getVirtualFileSystemView()
206: .getDisplayName(vfDir);
207: m_sFileName = vfDir.getVFS().getVirtualFileSystemView()
208: .getLogicalFileName(vfDir);
209:
210: String sValue = ConfigStore.getInstance().getPropertyValue(
211: "FILENAME_DISPLAY");
212: if (sValue != null && sValue.length() > 0
213: && sValue.equals("FILENAME")) {
214: this .setTitle(m_sFileName);
215: } else {
216: this .setTitle(m_sDisplayName);
217: }
218:
219: this .m_OrderServerButton.setVisible(vfDir
220: .isOrderableDirectory());
221: this .m_orderChooser.setVisible(true);
222: if (!ce.getPath().startsWith(HarmonisePaths.PATH_USERS)) {
223: this .m_displayChooser.setVisible(true);
224: }
225: } else if (ce.CONTEXT_TYPE == ContextType.CONTEXT_TABS) {
226: this .setTitle("");
227: this .m_orderChooser.setVisible(false);
228: this .m_OrderServerButton.setVisible(false);
229: this .m_displayChooser.setVisible(false);
230: } else if (ce.CONTEXT_TYPE == ContextType.CONTEXT_FILENAME_DISPLAY) {
231: String sValue = ConfigStore.getInstance().getPropertyValue(
232: "FILENAME_DISPLAY");
233: if (sValue != null && sValue.length() > 0
234: && sValue.equals("FILENAME")) {
235: this .m_displayChooser
236: .setSelectedItem("Display resource filename");
237: this .setTitle(this .m_sFileName);
238: } else if (sValue != null && sValue.length() > 0
239: && sValue.equals("ID")) {
240: this .m_displayChooser
241: .setSelectedItem("Display resource harmonise id");
242: this .setTitle(this .m_sFileName);
243: } else {
244: this .m_displayChooser
245: .setSelectedItem("Display resource title");
246: this .setTitle(this .m_sDisplayName);
247: }
248: this .revalidate();
249: this .repaint();
250: }
251: }
252:
253: /**
254: * Returns table view.
255: *
256: * @return Table view
257: */
258: public TableView getTable() {
259: return m_table;
260: }
261:
262: /**
263: * Sets the table view.
264: *
265: * @param view Table view
266: */
267: public void setTable(TableView view) {
268: m_table = view;
269: if (m_table.getOrderType().equals(TableView.ORDER_DATE)) {
270: this .m_orderChooser.setSelectedItem("View by date");
271: } else if (m_table.getOrderType().equals(TableView.ORDER_NAME)) {
272: this .m_orderChooser.setSelectedItem("View by name");
273: } else if (m_table.getOrderType()
274: .equals(TableView.ORDER_SERVER)) {
275: this .m_orderChooser
276: .setSelectedItem("View by default order");
277: }
278: }
279:
280: /* (non-Javadoc)
281: * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
282: */
283: public void actionPerformed(ActionEvent ae) {
284: if (ae.getActionCommand().equals("ORDER")) {
285: JFrame frame = new JFrame();
286: frame.setIconImage(((ImageIcon) IconManager.getInstance()
287: .getIcon("32-sim-logo.gif")).getImage());
288:
289: ContextEvent ce = ContextHandler.getInstance()
290: .getLastEvent(ContextType.CONTEXT_DIRS);
291: VirtualFile vfDir = ce.getVFS()
292: .getVirtualFile(ce.getPath()).getResource();
293:
294: OrderDialog dialog = new OrderDialog(frame,
295: "Set Default order", vfDir);
296: dialog.show();
297: if (dialog.isOrderChanged()) {
298: this .m_orderChooser
299: .setSelectedItem("View by default order");
300: this .m_table.setOrderType(TableView.ORDER_SERVER);
301: }
302: } else if (ae.getActionCommand().equals("ORDER_CHOOSER")) {
303: if (this .m_orderChooser.getSelectedItem().equals(
304: "View by name")) {
305: this .m_table.setOrderType(TableView.ORDER_NAME);
306: } else if (this .m_orderChooser.getSelectedItem().equals(
307: "View by date")) {
308: this .m_table.setOrderType(TableView.ORDER_DATE);
309: } else if (this .m_orderChooser.getSelectedItem().equals(
310: "View by default order")) {
311: this .m_table.setOrderType(TableView.ORDER_SERVER);
312: }
313: } else if (ae.getActionCommand().equals("DISPLAY_CHOOSER")) {
314: if (this .m_displayChooser.getSelectedItem().equals(
315: "Display resource filename")) {
316: ConfigStore.getInstance().setProperty(
317: "FILENAME_DISPLAY", "FILENAME");
318: } else if (this .m_displayChooser.getSelectedItem().equals(
319: "Display resource harmonise id")) {
320: ConfigStore.getInstance().setProperty(
321: "FILENAME_DISPLAY", "ID");
322: } else {
323: ConfigStore.getInstance().setProperty(
324: "FILENAME_DISPLAY", "DISPLAYNAME");
325: }
326: ContextEvent ce = new ContextEvent(
327: ContextType.CONTEXT_FILENAME_DISPLAY);
328: ContextHandler.getInstance().fireContextEvent(ce);
329: }
330: }
331:
332: }
|