I have begun to work with a Swing application with some gui classes extending JPanel. They are extending JPanel
and their name is always finished with HandlerPanel. Some of them are implementing a Hanlder
interface with this structure:
public interface Handler {
void handle(Message message);
}
but not all of them. Still all of them are containing Handler name in their name. Beside the handle method all of them have start and stop method. The main handler panel structure is like this.
public class HandlerPanel extends JPanel implements Handler {
/**
* Start listeners.
*/
public void start() {
// Default is no action!
}
/**
* Stop listeners.
*/
public void stop() {
// Default is no action!
}
@Override
public void handle(Message message) {
}
}
Problem is that not all of classes containing HandlerPanel are extending HandlerPanel and they don't have the handle method as well but they have start and stop method. The classes which are not implementing HandlerPanel and contians HandlerPanel at the end of their names are typically called via an extension of JDialog with structure:
public class ExampleDialog extends JDialog implements Stoppable {
private ExampleHandlerPanel panel;
public ExampleDialog (JFrame owner) {
super(owner, "title");
drawDialog();
}
public void start() {
panel.start();
}
/**
* Shall be called when this dialog is closed.
*/
@Override
public void stop() {
panel.stop();
this.setVisible(false);
}
private void drawDialog() {
JPanel basePanel = new JPanel();
basePanel.setLayout(new GridBagLayout());
panel= new ExampleHandlerPanel (this);
basePanel.add(paramPanel,
new GridBagConstraints(0, 0, 1, 1, 1.0, 1.0, GridBagConstraints.PAGE_START, GridBagConstraints.HORIZONTAL, new Insets(0,0,0,0), 0, 0));
}
}
the Stoppable
interface is like this:
public interface Stoppable {
void stop();
}
The structure of ExampleHandlerPanel is like this:
class ExampleHandlerPanel extends JPanel {
/**
* The constructor.
*
* @param ownerFrame frame who owns this panel
*/
ExampleHandlerPanel(JDialog ownerFrame) {
itsOwnerFrame = ownerFrame;
}
/**
* drawing panel content
*/
private void drawDialog() {
// drawing panel content
}
/**
* Shall be called when this dialog is opened.
*/
public void start() {
this.drawDialog();
}
}
/**
* Shall be called when this dialog is closed.
*/
public void stop() {
}
}
Now I want to refactor classes so that the classes which are not extending HandlerPanel contains the name Panel and I want to extract an interface containing both stop and start method which all of panels (extending HandlerPanel or Not) are implementing it. The interface will contain methods start()
and stop()
. I can not find a proper name for addressing both stop and start methods considering that we have an Stoppable interface already. Beside that start and stop doesn't feel as good names for a panel. Any suggestions? I wonder if there is design patterns for such graphical patterns.
Aucun commentaire:
Enregistrer un commentaire