[virtualcommons-svn] commit/foraging: alllee: refactoring UI with new csidex changes
Status: Beta
Brought to you by:
alllee
From: Bitbucket <com...@bi...> - 2011-12-01 00:10:15
|
1 new commit in foraging: https://bitbucket.org/virtualcommons/foraging/changeset/e68a44ef1fbb/ changeset: e68a44ef1fbb user: alllee date: 2011-12-01 01:10:01 summary: refactoring UI with new csidex changes affected #: 7 files diff -r 30d71ee1044bf4bf545bf64158896314211d64b6 -r e68a44ef1fbb46a45a5cb5fc018598c562e061e8 src/main/java/edu/asu/commons/foraging/client/ForagingClient.java --- a/src/main/java/edu/asu/commons/foraging/client/ForagingClient.java +++ b/src/main/java/edu/asu/commons/foraging/client/ForagingClient.java @@ -53,12 +53,12 @@ /** - * $Id: ForagingClient.java 529 2010-08-17 00:08:01Z alllee $ + * $Id$ * * Client for costly sanctioning experiments. Encompasses both 2D and 3D. * * @author <a href='mailto:mailto:All...@as...'>Allen Lee</a> - * @version $Revision: 529 $ + * @version $Revision$ */ public class ForagingClient extends BaseClient<ServerConfiguration> { @@ -235,7 +235,6 @@ private void initialize2DEventProcessors() { addEventProcessor(new EventTypeProcessor<BeginChatRoundRequest>(BeginChatRoundRequest.class) { public void handle(BeginChatRoundRequest request) { - System.err.println("Starting chat round"); dataModel.initialize(request.getGroupDataModel()); getGameWindow2D().initializeChatPanel(); } @@ -417,7 +416,7 @@ frame.setTitle("Client Window: " + client.getId()); frame.add(client.clientPanel); frame.setVisible(true); - frame.setExtendedState(frame.getExtendedState() | Frame.MAXIMIZED_BOTH); + frame.setExtendedState(Frame.MAXIMIZED_BOTH); frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); frame.pack(); } diff -r 30d71ee1044bf4bf545bf64158896314211d64b6 -r e68a44ef1fbb46a45a5cb5fc018598c562e061e8 src/main/java/edu/asu/commons/foraging/facilitator/FacilitatorWindow.java --- a/src/main/java/edu/asu/commons/foraging/facilitator/FacilitatorWindow.java +++ b/src/main/java/edu/asu/commons/foraging/facilitator/FacilitatorWindow.java @@ -28,9 +28,9 @@ import edu.asu.commons.foraging.event.QuizCompletedEvent; import edu.asu.commons.foraging.event.TrustGameSubmissionEvent; import edu.asu.commons.foraging.model.ClientData; -import edu.asu.commons.foraging.ui.ForagingInterface; import edu.asu.commons.net.Identifier; -import edu.asu.commons.util.HtmlEditorPane; +import edu.asu.commons.ui.HtmlEditorPane; +import edu.asu.commons.ui.UserInterfaceUtils; @@ -220,7 +220,7 @@ setLayout(new BorderLayout(3, 3)); // setBackground(Color.WHITE); - informationEditorPane = ForagingInterface.createInstructionsEditorPane(); + informationEditorPane = UserInterfaceUtils.createInstructionsEditorPane(); @@ -232,7 +232,7 @@ JPanel messagePanel = new JPanel(new BorderLayout()); JLabel messagePanelLabel = new JLabel("System messages"); - messagePanelLabel.setFont(ForagingInterface.DEFAULT_PLAIN_FONT); + messagePanelLabel.setFont(UserInterfaceUtils.DEFAULT_PLAIN_FONT); messagePanel.add(messagePanelLabel, BorderLayout.NORTH); Dimension minimumSize = new Dimension(600, 200); messagePanel.setMinimumSize(minimumSize); @@ -243,7 +243,7 @@ messagePanel.add(facilitatorChatPanel.getComponent(), BorderLayout.CENTER); } else { - messageEditorPane = ForagingInterface.createInstructionsEditorPane(); + messageEditorPane = UserInterfaceUtils.createInstructionsEditorPane(); JScrollPane messageScrollPane = new JScrollPane(messageEditorPane); messagePanel.add(messageScrollPane, BorderLayout.CENTER); } diff -r 30d71ee1044bf4bf545bf64158896314211d64b6 -r e68a44ef1fbb46a45a5cb5fc018598c562e061e8 src/main/java/edu/asu/commons/foraging/ui/ChatPanel.java --- a/src/main/java/edu/asu/commons/foraging/ui/ChatPanel.java +++ b/src/main/java/edu/asu/commons/foraging/ui/ChatPanel.java @@ -18,20 +18,20 @@ import edu.asu.commons.event.ChatEvent; import edu.asu.commons.event.ChatRequest; -import edu.asu.commons.event.EventChannel; import edu.asu.commons.event.EventTypeProcessor; import edu.asu.commons.experiment.DataModel; import edu.asu.commons.foraging.client.ForagingClient; import edu.asu.commons.foraging.conf.RoundConfiguration; import edu.asu.commons.net.Identifier; +import edu.asu.commons.ui.UserInterfaceUtils; /** - * $Id: ChatPanel.java 516 2010-05-10 23:31:53Z alllee $ + * $Id$ * * Chat panel used to communicate with other players. * * @author alllee - * @version $Revision: 516 $ + * @version $Revision$ */ @SuppressWarnings("serial") public class ChatPanel extends JPanel { @@ -46,24 +46,30 @@ private TextEntryPanel textEntryPanel; - public ChatPanel(EventChannel channel) { - channel.add(this, new EventTypeProcessor<ChatEvent>(ChatEvent.class) { + public ChatPanel(ForagingClient client) { + this(client, false); + } + + + public ChatPanel(ForagingClient client, boolean isInRoundChat) { + this.client = client; + client.getEventChannel().add(this, new EventTypeProcessor<ChatEvent>(ChatEvent.class) { public void handle(final ChatEvent chatEvent) { displayMessage(chatEvent.getSource(), chatEvent.toString()); } }); - initGuiComponents(); - } - - public ChatPanel(ForagingClient client) { - this(client.getEventChannel()); - this.client = client; + initGuiComponents(isInRoundChat); } - private void initGuiComponents() { + private void initGuiComponents(boolean isInRoundChat) { setLayout(new BorderLayout(3, 3)); setName("Chat panel"); - messagesEditorPane = ForagingInterface.createInstructionsEditorPane(); + if (! isInRoundChat) { + JEditorPane instructionsEditorPane = UserInterfaceUtils.createInstructionsEditorPane(); + + + } + messagesEditorPane = UserInterfaceUtils.createInstructionsEditorPane(); messageScrollPane = new JScrollPane(messagesEditorPane); textEntryPanel = new TextEntryPanel(client); @@ -133,7 +139,7 @@ }); JLabel headerLabel = new JLabel("Chat"); - headerLabel.setFont(ForagingInterface.DEFAULT_BOLD_FONT); + headerLabel.setFont(UserInterfaceUtils.DEFAULT_BOLD_FONT); add(headerLabel, BorderLayout.NORTH); add(chatField, BorderLayout.CENTER); } diff -r 30d71ee1044bf4bf545bf64158896314211d64b6 -r e68a44ef1fbb46a45a5cb5fc018598c562e061e8 src/main/java/edu/asu/commons/foraging/ui/ForagingInterface.java --- a/src/main/java/edu/asu/commons/foraging/ui/ForagingInterface.java +++ /dev/null @@ -1,122 +0,0 @@ -package edu.asu.commons.foraging.ui; - -import java.awt.Color; -import java.awt.Font; - -import javax.swing.JEditorPane; -import javax.swing.UIManager; -import javax.swing.text.html.HTMLDocument; - -import edu.asu.commons.util.HtmlEditorPane; - -/** - * $Id$ - * - * static utility class for common UI methods to set up a consistent look & feel. - * - * - * @author <a href='mailto:all...@as...'>Allen Lee</a> - * @version $Rev$ - */ -public final class ForagingInterface { - - public static final Font DEFAULT_PLAIN_FONT = new Font(getDefaultFont().getFamily(), Font.PLAIN, 16); - public static final Font DEFAULT_BOLD_FONT = new Font(getDefaultFont().getFamily(), Font.BOLD, 16); - - /** A very dark red color. */ - public static final Color VERY_DARK_RED = new Color(0x80, 0x00, 0x00); - - /** A dark red color. */ - public static final Color DARK_RED = new Color(0xc0, 0x00, 0x00); - - /** A light red color. */ - public static final Color LIGHT_RED = new Color(0xFF, 0x40, 0x40); - - /** A very light red color. */ - public static final Color VERY_LIGHT_RED = new Color(0xFF, 0x80, 0x80); - - /** A very dark yellow color. */ - public static final Color VERY_DARK_YELLOW = new Color(0x80, 0x80, 0x00); - - /** A dark yellow color. */ - public static final Color DARK_YELLOW = new Color(0xC0, 0xC0, 0x00); - - /** A light yellow color. */ - public static final Color LIGHT_YELLOW = new Color(0xFF, 0xFF, 0x40); - - /** A very light yellow color. */ - public static final Color VERY_LIGHT_YELLOW = new Color(0xFF, 0xFF, 0x80); - - /** A very dark green color. */ - public static final Color VERY_DARK_GREEN = new Color(0x00, 0x80, 0x00); - - /** A dark green color. */ - public static final Color DARK_GREEN = new Color(0x00, 0xC0, 0x00); - - /** A light green color. */ - public static final Color LIGHT_GREEN = new Color(0x40, 0xFF, 0x40); - - /** A very light green color. */ - public static final Color VERY_LIGHT_GREEN = new Color(0x80, 0xFF, 0x80); - - /** A very dark cyan color. */ - public static final Color VERY_DARK_CYAN = new Color(0x00, 0x80, 0x80); - - /** A dark cyan color. */ - public static final Color DARK_CYAN = new Color(0x00, 0xC0, 0xC0); - - /** A light cyan color. */ - public static final Color LIGHT_CYAN = new Color(0x40, 0xFF, 0xFF); - - /** Aa very light cyan color. */ - public static final Color VERY_LIGHT_CYAN = new Color(0x80, 0xFF, 0xFF); - - /** A very dark blue color. */ - public static final Color VERY_DARK_BLUE = new Color(0x00, 0x00, 0x80); - - /** A dark blue color. */ - public static final Color DARK_BLUE = new Color(0x00, 0x00, 0xC0); - - /** A light blue color. */ - public static final Color LIGHT_BLUE = new Color(0x40, 0x40, 0xFF); - - /** A very light blue color. */ - public static final Color VERY_LIGHT_BLUE = new Color(0x80, 0x80, 0xFF); - - /** A very dark magenta/purple color. */ - public static final Color VERY_DARK_MAGENTA = new Color(0x80, 0x00, 0x80); - - /** A dark magenta color. */ - public static final Color DARK_MAGENTA = new Color(0xC0, 0x00, 0xC0); - - /** A light magenta color. */ - public static final Color LIGHT_MAGENTA = new Color(0xFF, 0x40, 0xFF); - - /** A very light magenta color. */ - public static final Color VERY_LIGHT_MAGENTA = new Color(0xFF, 0x80, 0xFF); - - - public static Font getDefaultFont() { - return UIManager.getFont("Label.font"); - } - - public static void addStyles(JEditorPane editorPane, int fontSize) { - editorPane.setContentType("text/html"); - Font font = getDefaultFont(); - String bodyRule = String.format("body { font-family: %s; font-size: %s pt; }", font.getFamily(), fontSize); - ((HTMLDocument) editorPane.getDocument()).getStyleSheet().addRule(bodyRule); - } - - public static HtmlEditorPane createInstructionsEditorPane() { - return createInstructionsEditorPane(false); - } - - public static HtmlEditorPane createInstructionsEditorPane(boolean editable) { - final HtmlEditorPane htmlPane = new HtmlEditorPane(); - htmlPane.setEditable(editable); - htmlPane.setDoubleBuffered(true); - htmlPane.setBackground(Color.WHITE); - ForagingInterface.addStyles(htmlPane, 16); - return htmlPane; - } -} diff -r 30d71ee1044bf4bf545bf64158896314211d64b6 -r e68a44ef1fbb46a45a5cb5fc018598c562e061e8 src/main/java/edu/asu/commons/foraging/ui/GameWindow2D.java --- a/src/main/java/edu/asu/commons/foraging/ui/GameWindow2D.java +++ b/src/main/java/edu/asu/commons/foraging/ui/GameWindow2D.java @@ -56,17 +56,18 @@ import edu.asu.commons.foraging.model.Direction; import edu.asu.commons.foraging.rules.ForagingRule; import edu.asu.commons.net.Identifier; +import edu.asu.commons.ui.HtmlEditorPane; +import edu.asu.commons.ui.UserInterfaceUtils; import edu.asu.commons.util.Duration; -import edu.asu.commons.util.HtmlEditorPane; /** - * $Id: GameWindow2D.java 529 2010-08-17 00:08:01Z alllee $ + * $Id$ * * The client-side view for forager - can be used by standalone Java * applications or Applets. * * @author <a href='mailto:All...@as...'>Allen Lee</a> - * @version $Revision: 529 $ + * @version $Revision$ */ public class GameWindow2D implements GameWindow { @@ -361,7 +362,7 @@ subjectView = new SubjectView(subjectViewSize, dataModel); // add instructions panel card - instructionsEditorPane = ForagingInterface.createInstructionsEditorPane(); + instructionsEditorPane = UserInterfaceUtils.createInstructionsEditorPane(); instructionsScrollPane = new JScrollPane(instructionsEditorPane); instructionsScrollPane.setDoubleBuffered(true); instructionsScrollPane.getViewport().setScrollMode(JViewport.BACKINGSTORE_SCROLL_MODE); @@ -377,9 +378,9 @@ // add labels to game panel // FIXME: replace with progress bar. timeLeftLabel = new JLabel("Connecting ..."); - timeLeftLabel.setFont(ForagingInterface.DEFAULT_BOLD_FONT); + timeLeftLabel.setFont(UserInterfaceUtils.DEFAULT_BOLD_FONT); informationLabel = new JLabel("Tokens collected: 0 "); - informationLabel.setFont(ForagingInterface.DEFAULT_BOLD_FONT); + informationLabel.setFont(UserInterfaceUtils.DEFAULT_BOLD_FONT); // latencyLabel = new JLabel("Latency: 0"); informationLabel.setBackground(Color.YELLOW); informationLabel.setForeground(Color.BLUE); @@ -399,7 +400,7 @@ // FIXME: setFont doesn't work here the way we want it to. messageTextPane = new JTextPane(); messageTextPane.setEditable(false); - messageTextPane.setFont(ForagingInterface.DEFAULT_BOLD_FONT); + messageTextPane.setFont(UserInterfaceUtils.DEFAULT_BOLD_FONT); messageTextPane.setBackground(Color.WHITE); addStyles(messageTextPane.getStyledDocument()); messageScrollPane = new JScrollPane(messageTextPane); @@ -719,7 +720,7 @@ private ChatPanel getInRoundChatPanel() { if (inRoundChatPanel == null) { - inRoundChatPanel = new ChatPanel(client); + inRoundChatPanel = new ChatPanel(client, true); } return inRoundChatPanel; } @@ -731,7 +732,7 @@ public void run() { JPanel panel = new JPanel(); panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS)); - JEditorPane trustGameInstructionsEditorPane = ForagingInterface.createInstructionsEditorPane(); + JEditorPane trustGameInstructionsEditorPane = UserInterfaceUtils.createInstructionsEditorPane(); JScrollPane scrollPane = new JScrollPane(trustGameInstructionsEditorPane); trustGameInstructionsEditorPane.setText(client.getCurrentRoundConfiguration().getTrustGameInstructions()); panel.add(scrollPane); @@ -794,7 +795,7 @@ if (votingPanel == null) { votingPanel = new JPanel(); votingPanel.setLayout(new BoxLayout(votingPanel, BoxLayout.Y_AXIS)); - votingInstructionsEditorPane = ForagingInterface.createInstructionsEditorPane(); + votingInstructionsEditorPane = UserInterfaceUtils.createInstructionsEditorPane(); JScrollPane scrollPane = new JScrollPane(votingInstructionsEditorPane); votingInstructionsEditorPane.setText(client.getCurrentRoundConfiguration().getVotingInstructions()); votingPanel.add(scrollPane); diff -r 30d71ee1044bf4bf545bf64158896314211d64b6 -r e68a44ef1fbb46a45a5cb5fc018598c562e061e8 src/main/java/edu/asu/commons/foraging/ui/InstructionsView.java --- a/src/main/java/edu/asu/commons/foraging/ui/InstructionsView.java +++ b/src/main/java/edu/asu/commons/foraging/ui/InstructionsView.java @@ -1,7 +1,6 @@ package edu.asu.commons.foraging.ui; import java.awt.BorderLayout; -import java.awt.Font; import javax.swing.JPanel; import javax.swing.JScrollPane; @@ -11,14 +10,15 @@ import edu.asu.commons.foraging.conf.RoundConfiguration; import edu.asu.commons.foraging.visualization.conceptual.AgentDesignPanel; import edu.asu.commons.foraging.visualization.forestry.AvatarDesignPanel; -import edu.asu.commons.util.HtmlEditorPane; +import edu.asu.commons.ui.HtmlEditorPane; +import edu.asu.commons.ui.UserInterfaceUtils; /** - * $Id: InstructionsView.java 529 2010-08-17 00:08:01Z alllee $ + * $Id$ * * @author <a href='All...@as...'>Allen Lee</a>, Deepali Bhagvat - * @version $Revision: 529 $ + * @version $Revision$ */ public class InstructionsView { @@ -30,22 +30,14 @@ private JPanel agentDesignPanel = null; public InstructionsView() { - instructionsEditorPane = createInstructionsEditorPane(); + instructionsEditorPane = UserInterfaceUtils.createInstructionsEditorPane(); instructionsScrollPane = new JScrollPane(instructionsEditorPane); mainPanel = new JPanel(); mainPanel.setLayout(new BorderLayout()); mainPanel.add(instructionsScrollPane, BorderLayout.CENTER); setInstructions("Please wait patiently until the other participants finish designing their avatars."); } - - private HtmlEditorPane createInstructionsEditorPane() { - final HtmlEditorPane htmlPane = new HtmlEditorPane(); - // htmlPane.setPreferredSize(new Dimension(400, 400)); - htmlPane.setEditable(false); - htmlPane.setFont(new Font("serif", Font.PLAIN, 12)); - return htmlPane; - } - + public void setInstructions(String instructions) { instructionsEditorPane.setText(instructions); instructionsEditorPane.setCaretPosition(0); diff -r 30d71ee1044bf4bf545bf64158896314211d64b6 -r e68a44ef1fbb46a45a5cb5fc018598c562e061e8 src/main/java/edu/asu/commons/foraging/ui/VotingForm.java --- a/src/main/java/edu/asu/commons/foraging/ui/VotingForm.java +++ b/src/main/java/edu/asu/commons/foraging/ui/VotingForm.java @@ -27,6 +27,7 @@ import edu.asu.commons.foraging.client.ForagingClient; import edu.asu.commons.foraging.rules.ForagingRule; +import edu.asu.commons.ui.UserInterfaceUtils; /** * @@ -67,11 +68,11 @@ GroupLayout.SequentialGroup verticalGroup = groupLayout.createSequentialGroup(); String rightColumnHeader = votingResults.isEmpty() ? "Select one" : "Nominations"; JLabel rightHeaderLabel = new JLabel(rightColumnHeader); - rightHeaderLabel.setFont(ForagingInterface.DEFAULT_BOLD_FONT); + rightHeaderLabel.setFont(UserInterfaceUtils.DEFAULT_BOLD_FONT); horizontalButtonParallelGroup.addComponent(rightHeaderLabel); JLabel ruleHeaderLabel = new JLabel("Rule"); - ruleHeaderLabel.setFont(ForagingInterface.DEFAULT_BOLD_FONT); + ruleHeaderLabel.setFont(UserInterfaceUtils.DEFAULT_BOLD_FONT); horizontalLabelParallelGroup.addComponent(ruleHeaderLabel); verticalGroup.addGroup(groupLayout.createParallelGroup(Alignment.BASELINE).addComponent(ruleHeaderLabel).addGap(10).addComponent(rightHeaderLabel)); @@ -79,7 +80,7 @@ for (ForagingRule rule: rules) { ruleIndex++; JLabel ruleLabel = new JLabel(String.format("Rule %d: %s", ruleIndex, rule)); - ruleLabel.setFont(ForagingInterface.DEFAULT_PLAIN_FONT); + ruleLabel.setFont(UserInterfaceUtils.DEFAULT_PLAIN_FONT); horizontalLabelParallelGroup.addComponent(ruleLabel); JComponent component = null; if (votingResults.isEmpty()) { Repository URL: https://bitbucket.org/virtualcommons/foraging/ -- This is a commit notification from bitbucket.org. You are receiving this because you have the service enabled, addressing the recipient of this email. |