Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Ch. 10, Mediators

  • Loading branch information...
commit 51fddefedb565eef47d4cad92d62809833b7d9e8 1 parent a685385
bostond authored
191 src/main/java/app/mediator/moveATub/MoveATub.java
... ... @@ -0,0 +1,191 @@
  1 +package app.mediator.moveATub;
  2 +
  3 +/*
  4 + * Copyright (c) 2001, 2005. Steven J. Metsker.
  5 + *
  6 + * Steve Metsker makes no representations or warranties about
  7 + * the fitness of this software for any particular purpose,
  8 + * including the implied warranty of merchantability.
  9 + *
  10 + * Please use this software as you wish with the sole
  11 + * restriction that you may not claim that you wrote it.
  12 + */
  13 +
  14 +import java.awt.*;
  15 +import java.awt.event.ActionEvent;
  16 +import java.awt.event.ActionListener;
  17 +import java.util.*;
  18 +import java.util.List;
  19 +
  20 +import javax.swing.*;
  21 +import javax.swing.event.ListSelectionEvent;
  22 +import javax.swing.event.ListSelectionListener;
  23 +
  24 +import com.oozinoz.ui.SwingFacade;
  25 +import com.oozinoz.ui.UI;
  26 +
  27 +/**
  28 + * This class is partially refactored, with a method for each control. The
  29 + * next step will be to create a mediator class, factoring the action logic
  30 + * out of this class.
  31 + */
  32 +public class MoveATub extends JPanel implements ListSelectionListener, ActionListener {
  33 + private static Hashtable tubMachine;
  34 +
  35 + private List boxes;
  36 + private JList boxList;
  37 +
  38 + private JList tubList;
  39 + private Object selectedTub;
  40 +
  41 + private JList machineList;
  42 + private Object selectedMachine;
  43 +
  44 + private JButton assignButton;
  45 +
  46 + private UI ui = UI.NORMAL;
  47 +
  48 + public static void main(String[] args) {
  49 + JFrame frame = SwingFacade.launch(new MoveATub(), "Move a Tub");
  50 + frame.setSize(600, 250);
  51 + frame.validate();
  52 + }
  53 +
  54 + public MoveATub() {
  55 + super(new GridLayout(1, 4));
  56 + setFont(ui.getFont());
  57 +
  58 + this.add(labeledPanel("From Machine...", boxList()));
  59 + this.add(labeledPanel("Move Tub...", tubList()));
  60 + this.add(labeledPanel("To Machine...", machineList()));
  61 + this.add(buttonPanel(assignButton()));
  62 + }
  63 +
  64 + private Component buttonPanel(JButton button) {
  65 + JPanel result = new JPanel(new GridLayout(3, 1));
  66 + result.add(new JLabel(" "));
  67 +
  68 + JPanel innerPanel = new JPanel(new FlowLayout(FlowLayout.CENTER));
  69 + innerPanel.add(button);
  70 + result.add(innerPanel);
  71 +
  72 + result.add(new JLabel(" "));
  73 + return result;
  74 + }
  75 +
  76 + private Component labeledPanel(String label, JList list) {
  77 + JPanel result = new JPanel(new BorderLayout());
  78 + result.add(new JLabel(label), BorderLayout.NORTH);
  79 + result.add(new JScrollPane(list), BorderLayout.CENTER);
  80 +
  81 + int borderWidth = 15;
  82 + result.setBorder(BorderFactory.createEmptyBorder(borderWidth, borderWidth, borderWidth, borderWidth));
  83 +
  84 + return result;
  85 + }
  86 +
  87 + // This is a temporary approach that has hard-coded literals
  88 + private List boxes() {
  89 + if (boxes == null) {
  90 + boxes = new ArrayList();
  91 + boxes.add("Mixer-2201");
  92 + boxes.add("Mixer-2202");
  93 + boxes.add("Fuser-2101");
  94 + boxes.add("StarPress-2401");
  95 + boxes.add("StarPress-2402");
  96 + boxes.add("Assembler-2301");
  97 + }
  98 + return boxes;
  99 + }
  100 +
  101 + private JList boxList() {
  102 + if (boxList == null) {
  103 + boxList = ui.createList(boxes().toArray());
  104 + boxList.addListSelectionListener(this);
  105 + }
  106 + return boxList;
  107 + }
  108 +
  109 + private JList machineList() {
  110 + if (machineList == null) {
  111 + machineList = ui.createList(boxes().toArray());
  112 + machineList.addListSelectionListener(this);
  113 + }
  114 + return machineList;
  115 + }
  116 +
  117 + private JList tubList() {
  118 + if (tubList == null) {
  119 + tubList = ui.createList(new String[] {});
  120 + tubList.addListSelectionListener(this);
  121 + }
  122 + return tubList;
  123 + }
  124 +
  125 + private JButton assignButton() {
  126 + if (assignButton == null) {
  127 + assignButton = new JButton("Do it!");
  128 + assignButton.setEnabled(false);
  129 + assignButton.addActionListener(this);
  130 + }
  131 + return assignButton;
  132 + }
  133 +
  134 + private static Hashtable tubMachine() {
  135 + if (tubMachine == null) {
  136 + tubMachine = new Hashtable();
  137 + tubMachine.put("T502", "Mixer-2201");
  138 + tubMachine.put("T503", "Mixer-2201");
  139 + tubMachine.put("T504", "Mixer-2201");
  140 + tubMachine.put("T101", "StarPress-2402");
  141 + tubMachine.put("T102", "StarPress-2402");
  142 + }
  143 + return tubMachine;
  144 + }
  145 +
  146 + private static List tubNames(String machineName) {
  147 + ArrayList result = new ArrayList();
  148 +
  149 + Enumeration iter = tubMachine().keys();
  150 + while (iter.hasMoreElements()) {
  151 + String key = iter.nextElement().toString();
  152 + String value = tubMachine().get(key).toString();
  153 + if (value.equals(machineName)) result.add(key);
  154 + }
  155 +
  156 + return result;
  157 + }
  158 +
  159 + private void updateTubList(String machineName) {
  160 + List tubs = tubNames(machineName);
  161 + tubList().setListData(tubs.toArray());
  162 + }
  163 +
  164 + public void valueChanged(ListSelectionEvent e) {
  165 + JList sender = (JList) e.getSource();
  166 +
  167 + if (!sender.isSelectionEmpty()) {
  168 + if (sender.equals(boxList()))
  169 + updateTubList(sender.getSelectedValue().toString());
  170 +
  171 + if (sender.equals(machineList()))
  172 + selectedMachine = sender.getSelectedValue();
  173 +
  174 + if (sender.equals(tubList()))
  175 + selectedTub = sender.getSelectedValue();
  176 + }
  177 +
  178 + assignButton().setEnabled(
  179 + !tubList().isSelectionEmpty() && !machineList().isSelectionEmpty());
  180 + }
  181 +
  182 + public void actionPerformed(ActionEvent e) {
  183 + if (selectedMachine == null || selectedTub == null) return;
  184 + String tubName = selectedTub.toString();
  185 + String fromMachineName = (String) tubMachine().get(tubName);
  186 + String toMachineName = selectedMachine.toString();
  187 + tubMachine().put(tubName, toMachineName);
  188 + updateTubList(fromMachineName);
  189 + assignButton().setEnabled(false);
  190 + }
  191 +}
111 src/main/java/app/mediator/moveATub2/MoveATub2.java
... ... @@ -0,0 +1,111 @@
  1 +package app.mediator.moveATub2;
  2 +
  3 +import java.awt.BorderLayout;
  4 +import java.awt.Component;
  5 +import java.awt.FlowLayout;
  6 +import java.awt.GridLayout;
  7 +
  8 +import javax.swing.BorderFactory;
  9 +import javax.swing.JButton;
  10 +import javax.swing.JFrame;
  11 +import javax.swing.JLabel;
  12 +import javax.swing.JList;
  13 +import javax.swing.JPanel;
  14 +import javax.swing.JScrollPane;
  15 +
  16 +import com.oozinoz.ui.SwingFacade;
  17 +import com.oozinoz.ui.UI;
  18 +
  19 +/**
  20 + * Refactored from MoveATub. Challenges 10.1 and 10.2 we exercised on what would
  21 + * change, but didn't ask for an implementation.
  22 + * @author bostond
  23 + *
  24 + */
  25 +
  26 +public class MoveATub2 extends JPanel {
  27 +
  28 + private static final long serialVersionUID = 8462238486128857207L;
  29 +
  30 + private JButton assignButton;
  31 +
  32 + private JList boxList;
  33 + private JList tubList;
  34 + private JList machineList;
  35 +
  36 + private UI ui = UI.NORMAL;
  37 +
  38 + private NameBase data = new NameBase();
  39 + private MoveATubMediator mediator;
  40 +
  41 + public static void main(String[] args) {
  42 + JFrame frame = SwingFacade.launch(new MoveATub2(), "Move a Tub2");
  43 + frame.setSize(600, 250);
  44 + frame.validate();
  45 + }
  46 +
  47 + public MoveATub2() {
  48 + super(new GridLayout(1, 4));
  49 + setFont(ui.getFont());
  50 +
  51 + this.mediator = new MoveATubMediator(this, data);
  52 +
  53 + this.add(labeledPanel("From Machine...", boxList()));
  54 + this.add(labeledPanel("Move Tub...", tubList()));
  55 + this.add(labeledPanel("To Machine...", machineList()));
  56 + this.add(buttonPanel(assignButton()));
  57 + }
  58 +
  59 + private Component buttonPanel(JButton button) {
  60 + JPanel result = new JPanel(new GridLayout(3, 1));
  61 + result.add(new JLabel(" "));
  62 +
  63 + JPanel innerPanel = new JPanel(new FlowLayout(FlowLayout.CENTER));
  64 + innerPanel.add(button);
  65 + result.add(innerPanel);
  66 +
  67 + result.add(new JLabel(" "));
  68 + return result;
  69 + }
  70 +
  71 + private Component labeledPanel(String label, JList list) {
  72 + JPanel result = new JPanel(new BorderLayout());
  73 + result.add(new JLabel(label), BorderLayout.NORTH);
  74 + result.add(new JScrollPane(list), BorderLayout.CENTER);
  75 +
  76 + int borderWidth = 15;
  77 + result.setBorder(BorderFactory.createEmptyBorder(borderWidth, borderWidth, borderWidth, borderWidth));
  78 +
  79 + return result;
  80 + }
  81 +
  82 + public JButton assignButton() {
  83 + if (assignButton == null) {
  84 + assignButton = new JButton("Do it!");
  85 + assignButton.setEnabled(false);
  86 + }
  87 + return assignButton;
  88 + }
  89 +
  90 + public JList boxList() {
  91 + if (boxList == null) {
  92 + boxList = ui.createList(data.boxes());
  93 + }
  94 + return boxList;
  95 + }
  96 +
  97 + public JList machineList() {
  98 + if (machineList == null) {
  99 + machineList = ui.createList(data.boxes());
  100 + }
  101 + return machineList;
  102 + }
  103 +
  104 + public JList tubList() {
  105 + if (tubList == null) {
  106 + tubList = ui.createList(new String[] {});
  107 + }
  108 + return tubList;
  109 + }
  110 +
  111 +}
100 src/main/java/app/mediator/moveATub2/MoveATubMediator.java
... ... @@ -0,0 +1,100 @@
  1 +package app.mediator.moveATub2;
  2 +
  3 +import java.awt.event.ActionEvent;
  4 +import java.awt.event.ActionListener;
  5 +
  6 +import javax.swing.JList;
  7 +import javax.swing.event.ListSelectionEvent;
  8 +import javax.swing.event.ListSelectionListener;
  9 +
  10 +/**
  11 + * Refactored from MoveATub. Challenges 10.1 and 10.2 we exercised on what would
  12 + * change, but didn't ask for an implementation.
  13 + * @author bostond
  14 + *
  15 + */
  16 +
  17 +public class MoveATubMediator implements ActionListener, ListSelectionListener {
  18 +
  19 + private MoveATub2 gui =null;
  20 + private NameBase data = null;
  21 +
  22 + private Object selectedMachine = null;
  23 + private Object selectedTub = null;
  24 +
  25 +
  26 +
  27 + public MoveATubMediator(MoveATub2 gui, NameBase data) {
  28 + this.gui = gui;
  29 +
  30 + gui.assignButton().addActionListener(this);
  31 + gui.boxList().addListSelectionListener(this);
  32 + gui.machineList().addListSelectionListener(this);
  33 + gui.tubList().addListSelectionListener(this);
  34 +
  35 + this.data = data;
  36 + }
  37 +
  38 + /**
  39 + * Upon notification of UI change: if the list changed is the
  40 + * source machine list, update the tub list with the selected machine's
  41 + * tubs, and set the selected machine value; if the list selected is the tub list,
  42 + * set the selected tub value; if the list is the destination machine
  43 + * list, update the selected destination machine value
  44 + */
  45 + public void valueChanged(ListSelectionEvent e) {
  46 + JList sender = (JList) e.getSource();
  47 +
  48 + if (!sender.isSelectionEmpty()) {
  49 + if (sender.equals(gui.boxList())) {
  50 + updateTubList(sender.getSelectedValue().toString());
  51 + updateMachineList(sender.getSelectedValue().toString()); // don't include the source machine in the destination machine list
  52 + }
  53 +
  54 + if (sender.equals(gui.machineList()))
  55 + selectedMachine = sender.getSelectedValue();
  56 +
  57 + if (sender.equals(gui.tubList()))
  58 + selectedTub = sender.getSelectedValue();
  59 + }
  60 +
  61 + gui.assignButton().setEnabled(
  62 + !gui.tubList().isSelectionEmpty() && !gui.machineList().isSelectionEmpty());
  63 + }
  64 +
  65 + /**
  66 + * Make selected changes - move tub across machines, then update GUI to
  67 + * reflect that the tub is now gone from the selected machine, then
  68 + * disable move button.
  69 + */
  70 + public void actionPerformed(ActionEvent e) {
  71 + if (selectedMachine == null || selectedTub == null) return;
  72 + String tubName = selectedTub.toString();
  73 + String fromMachineName = data.getMachineContaining(tubName);
  74 + String toMachineName = selectedMachine.toString();
  75 + data.put(tubName, toMachineName);
  76 +
  77 + updateTubList(fromMachineName);
  78 +
  79 + gui.assignButton().setEnabled(false);
  80 + }
  81 +
  82 + public void updateTubList(String machinename) {
  83 + gui.tubList().setListData(data.tubNames(machinename));
  84 + }
  85 +
  86 + public void updateMachineList(String machinename) {
  87 + Object[] targets = data.boxes();
  88 + Object[] selectableBoxes = new Object[targets.length - 1];
  89 + int position = 0;
  90 + for (Object o : targets) {
  91 + if (! o.equals(machinename)) {
  92 + selectableBoxes[position++] = o;
  93 + }
  94 + }
  95 + gui.machineList().setListData(selectableBoxes);
  96 + }
  97 +
  98 +
  99 +
  100 +}
79 src/main/java/app/mediator/moveATub2/NameBase.java
... ... @@ -0,0 +1,79 @@
  1 +package app.mediator.moveATub2;
  2 +
  3 +import java.util.ArrayList;
  4 +import java.util.Iterator;
  5 +import java.util.LinkedHashMap;
  6 +import java.util.LinkedHashSet;
  7 +import java.util.List;
  8 +import java.util.Map;
  9 +import java.util.Set;
  10 +
  11 +/**
  12 + * Refactored from MoveATub. Challenges 10.1 and 10.2 we exercised on what would
  13 + * change, but didn't ask for an implementation.
  14 + * @author bostond
  15 + *
  16 + */
  17 +
  18 +public class NameBase {
  19 + private List boxes;
  20 +
  21 + protected Map<String, String> tubToMachine = null;
  22 +
  23 + public NameBase() {
  24 +
  25 + tubToMachine = new LinkedHashMap<String, String>();
  26 +
  27 + tubToMachine.put("T502", "Mixer-2201");
  28 + tubToMachine.put("T503", "Mixer-2201");
  29 + tubToMachine.put("T504", "Mixer-2201");
  30 + tubToMachine.put("T101", "StarPress-2402");
  31 + tubToMachine.put("T102", "StarPress-2402");
  32 +
  33 + }
  34 +
  35 + public Object[] boxes()
  36 + {
  37 + if (boxes == null)
  38 + {
  39 + boxes = new ArrayList();
  40 + boxes.add("Mixer-2201");
  41 + boxes.add("Mixer-2202");
  42 + boxes.add("Fuser-2101");
  43 + boxes.add("StarPress-2401");
  44 + boxes.add("StarPress-2402");
  45 + boxes.add("Assembler-2301");
  46 + }
  47 + return boxes.toArray();
  48 + }
  49 +
  50 + public Object[] tubNames(String machineName) {
  51 + Set<String> set = new LinkedHashSet<String>();
  52 + Iterator<Map.Entry<String, String>> i = tubToMachine.entrySet().iterator();
  53 +
  54 + while (i.hasNext()) {
  55 + Map.Entry<String, String> e = i.next();
  56 + if (e.getValue().equals(machineName)) {
  57 + set.add(e.getKey());
  58 + }
  59 + }
  60 +
  61 + return set.toArray();
  62 +
  63 + }
  64 +
  65 + public String getMachineContaining(String tubName) {
  66 + return tubToMachine.get(tubName);
  67 + }
  68 +
  69 +
  70 + public void put(String tubName, String toMachineName) {
  71 + tubToMachine.put(tubName, toMachineName);
  72 + }
  73 +
  74 +
  75 +
  76 +
  77 +
  78 +
  79 +}
78 src/main/java/com/oozinoz/machine/Tub.java
... ... @@ -0,0 +1,78 @@
  1 +package com.oozinoz.machine;
  2 +
  3 +/*
  4 + * Copyright (c) 2001, 2005. Steven J. Metsker.
  5 + *
  6 + * Steve Metsker makes no representations or warranties about
  7 + * the fitness of this software for any particular purpose,
  8 + * including the implied warranty of merchantability.
  9 + *
  10 + * Please use this software as you wish with the sole
  11 + * restriction that you may not claim that you wrote it.
  12 + */
  13 +
  14 +/**
  15 +* A tub is a standard, rubber container that contains
  16 +* about four liters of a chemical. This class is a minimal
  17 +* model that helps show how to manage a one-to-many
  18 +* relation in an object model.
  19 +*/
  20 +public class Tub {
  21 + private String id;
  22 +
  23 + private TubMediator mediator = null;
  24 +
  25 + /**
  26 + * Create a tub with the given id and managed by the given
  27 + * mediator.
  28 + * @param id the identity of this machine
  29 + */
  30 + public Tub(String id, TubMediator mediator) {
  31 + this.id = id;
  32 + this.mediator = mediator;
  33 + }
  34 +
  35 + /**
  36 + * Use a mediator to control getting and setting the location
  37 + * of this tub. This prevents a tub from ever being modeled as
  38 + * being on two machines at once.
  39 + */
  40 + public Machine getLocation() {
  41 + return mediator.getMachine(this);
  42 + }
  43 +
  44 + public void setLocation(Machine value) {
  45 + mediator.set(this, value);
  46 + }
  47 +
  48 + /**
  49 + * @return a textual representation of this tub.
  50 + */
  51 + public String toString() {
  52 + return id;
  53 + }
  54 +
  55 + /**
  56 + * @return a unique id for this tub.
  57 + */
  58 + public int hashCode() {
  59 + return id.hashCode();
  60 + }
  61 +
  62 + /**
  63 + * @return true if, according to business rules, this
  64 + * component and the supplied object refer to the same
  65 + * thing.
  66 + * @param o The candidate to compare to
  67 + */
  68 + public boolean equals(Object obj) {
  69 + if (obj == this)
  70 + return true;
  71 +
  72 + if (obj.getClass() != Tub.class)
  73 + return false;
  74 +
  75 + Tub that = (Tub) obj;
  76 + return id.equals(that.id);
  77 + }
  78 +}
44 src/main/java/com/oozinoz/machine/TubMediator.java
... ... @@ -0,0 +1,44 @@
  1 +package com.oozinoz.machine;
  2 +
  3 +import java.util.HashMap;
  4 +import java.util.HashSet;
  5 +import java.util.Iterator;
  6 +import java.util.Map;
  7 +import java.util.Set;
  8 +
  9 +/**
  10 + * Challenge 10.4 (+class, + getMachine(), + setMachine())
  11 + * @author bostond
  12 + *
  13 + */
  14 +
  15 +public class TubMediator {
  16 +
  17 + protected Map<Tub, Machine> tubToMachine = new HashMap<Tub, Machine>();
  18 +
  19 + public Machine getMachine(Tub t) {
  20 + return tubToMachine.get(t);
  21 + }
  22 +
  23 + public Set<Tub> getTubs(Machine m) {
  24 +
  25 + Set<Tub> set = new HashSet<Tub>();
  26 + Iterator<Map.Entry<Tub, Machine>> i = tubToMachine.entrySet().iterator();
  27 +
  28 + while (i.hasNext()) {
  29 + Map.Entry<Tub, Machine> e = i.next();
  30 + if (e.getValue().equals(m)) {
  31 + set.add(e.getKey());
  32 + }
  33 + }
  34 +
  35 + return set;
  36 +
  37 + }
  38 +
  39 + public void set(Tub t, Machine m) {
  40 + tubToMachine.put(t, m);
  41 + }
  42 +
  43 +
  44 +}
133 src/main/java/com/oozinoz/ui/UI.java
... ... @@ -0,0 +1,133 @@
  1 +package com.oozinoz.ui;
  2 +
  3 +/*
  4 + * Copyright (c) 2001, 2005. Steven J. Metsker.
  5 + *
  6 + * Steve Metsker makes no representations or warranties about
  7 + * the fitness of this software for any particular purpose,
  8 + * including the implied warranty of merchantability.
  9 + *
  10 + * Please use this software as you wish with the sole
  11 + * restriction that you may not claim that you wrote it.
  12 + */
  13 +
  14 +import java.awt.*;
  15 +
  16 +import javax.swing.*;
  17 +import javax.swing.border.BevelBorder;
  18 +import javax.swing.border.TitledBorder;
  19 +
  20 +/**
  21 + * User interface utilities.
  22 + */
  23 +
  24 +public class UI {
  25 + protected Font font = new Font("Book Antiqua", Font.PLAIN, 18);
  26 +
  27 + public static final int STANDARD_PAD = 10;
  28 +
  29 + public static final UI NORMAL = new UI();
  30 +
  31 + /**
  32 + * @return a standard font that subclasses can override
  33 + */
  34 + public Font getFont() {
  35 + return font;
  36 + }
  37 +
  38 + /**
  39 + * @return a standard padding amount that subclasses can override
  40 + */
  41 + public int getPad() {
  42 + return STANDARD_PAD;
  43 + }
  44 +
  45 + /**
  46 + * @return a standard button
  47 + */
  48 + public JButton createButton() {
  49 + JButton button = new JButton();
  50 + button.setSize(128, 128);
  51 + button.setFont(getFont());
  52 + button.setVerticalTextPosition(SwingConstants.BOTTOM);
  53 + button.setHorizontalTextPosition(SwingConstants.CENTER);
  54 + return button;
  55 + }
  56 +
  57 + /**
  58 + * @return a standard OK! (or affirmation) button
  59 + */
  60 + public JButton createButtonOk() {
  61 + JButton button = createButton();
  62 + button.setIcon(getIcon("images/rocket-large.gif"));
  63 + button.setText("Ok!");
  64 + return button;
  65 + }
  66 +
  67 + /**
  68 + * @return a standard Cancel! (or negation) button
  69 + */
  70 + public JButton createButtonCancel() {
  71 + JButton button = createButton();
  72 + button.setIcon(getIcon("images/rocket-large-down.gif"));
  73 + button.setText("Cancel!");
  74 + return button;
  75 + }
  76 +
  77 + /**
  78 + * @return a panel with a standard amount of padding around any controls
  79 + */
  80 + public JPanel createPaddedPanel() {
  81 + JPanel panel = new JPanel();
  82 + panel.setBorder(
  83 + BorderFactory.createEmptyBorder(getPad(), getPad(), getPad(), getPad()));
  84 + return panel;
  85 + }
  86 +
  87 + /**
  88 + * @return a panel with a standard amount of padding around any particular
  89 + * control
  90 + * @param c
  91 + * the control
  92 + */
  93 + public JPanel createPaddedPanel(Component c) {
  94 + JPanel panel = createPaddedPanel();
  95 + panel.add(c);
  96 + return panel;
  97 + }
  98 +
  99 + public static Icon getIcon(String imageName) {
  100 + return new ImageIcon(imageName);
  101 + }
  102 +
  103 + public JList createList(Object[] contents) {
  104 + JList result = new JList(contents);
  105 + result.setFont(getFont());
  106 + result.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
  107 + return result;
  108 + }
  109 +
  110 + /**
  111 + * @return a titled border with the given title.
  112 + */
  113 + public TitledBorder createTitledBorder(String title) {
  114 + TitledBorder border = BorderFactory.createTitledBorder(
  115 + BorderFactory.createBevelBorder(BevelBorder.RAISED),
  116 + title,
  117 + TitledBorder.LEFT,
  118 + TitledBorder.TOP);
  119 + border.setTitleColor(Color.black);
  120 + border.setTitleFont(getFont());
  121 + return border;
  122 + }
  123 +
  124 + /**
  125 + * @return a new panel that wraps a titled border around a given panel.
  126 + */
  127 + public JPanel createTitledPanel(String title, JPanel in) {
  128 + JPanel out = new JPanel();
  129 + out.add(in);
  130 + out.setBorder(createTitledBorder(title));
  131 + return out;
  132 + }
  133 +}

0 comments on commit 51fddef

Please sign in to comment.
Something went wrong with that request. Please try again.