EMMA Coverage Report (generated Tue Feb 12 22:23:49 ICT 2008)
[all classes][net.sourceforge.hivegui.message]

COVERAGE SUMMARY FOR SOURCE FILE [MessageFactory.java]

nameclass, %method, %block, %line, %
MessageFactory.java0%   (0/1)0%   (0/3)0%   (0/110)0%   (0/26)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class MessageFactory0%   (0/1)0%   (0/3)0%   (0/110)0%   (0/26)
<static initializer> 0%   (0/1)0%   (0/4)0%   (0/1)
MessageFactory (ApplicationContext): void 0%   (0/1)0%   (0/9)0%   (0/3)
message (String, Object []): UserChoice 0%   (0/1)0%   (0/97)0%   (0/22)

1//  Copyright 2004-2007 Jean-Francois Poilpret
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7//     http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14 
15package net.sourceforge.hivegui.message;
16 
17import java.awt.Window;
18 
19import javax.swing.JDialog;
20import javax.swing.JFrame;
21import javax.swing.JOptionPane;
22 
23import org.apache.commons.logging.Log;
24import org.apache.commons.logging.LogFactory;
25import org.jdesktop.application.ApplicationContext;
26import org.jdesktop.application.Resource;
27import org.jdesktop.application.ResourceMap;
28 
29import net.sourceforge.hivegui.component.ActiveWindowHolder;
30 
31public class MessageFactory
32{
33        static private final Log        _logger = LogFactory.getLog(MessageFactory.class);
34 
35        public MessageFactory(ApplicationContext context)
36        {
37                _map = context.getResourceMap(getClass());
38        }
39        
40        public UserChoice        message(String id, Object... args)
41        {
42                try
43                {
44                        _map.injectFields(this, id);
45                        String title = String.format(_title, args);
46                        String message = String.format(_message, args);
47                        
48                        JOptionPane pane = new JOptionPane(        message,
49                                                                                                _messageType.value(),
50                                                                                                _optionType.value());
51                        pane.setName("message-" + id);
52                        Window parent = ActiveWindowHolder.instance().getActiveWindow();
53                        JDialog box;
54                        if (parent instanceof JFrame)
55                        {
56                                box = pane.createDialog(parent, title);
57                        }
58                        else if (parent instanceof JDialog)
59                        {
60                                box = pane.createDialog(parent, title);
61                        }
62                        else
63                        {
64                                box = pane.createDialog((JFrame) null, title);
65                        }
66                        box.setLocationRelativeTo(parent);
67                        box.setVisible(true);
68                        Integer result = (Integer) pane.getValue();
69                        if (result == null)
70                        {
71                                return UserChoice.CANCEL;
72                        }
73                        else
74                        {
75                                return UserChoice.get(result.intValue());
76                        }
77                }
78                catch (ResourceMap.InjectFieldException e)
79                {
80                        _logger.error("message() unexisting id <" + id + ">", e);
81                        return null;
82                }
83        }
84 
85        final private ResourceMap        _map;
86 
87        @Resource(key = "messageType")
88        private MessageType        _messageType;
89        @Resource(key = "optionType")
90        private OptionType        _optionType;
91        @Resource(key = "title")
92        private String                _title;
93        @Resource(key = "message")
94        private String                _message;
95}

[all classes][net.sourceforge.hivegui.message]
EMMA 2.0.5312 (C) Vladimir Roubtsov