维护和控制GUI状态和子状态(Maintain and control GUI states and substates)

系统教程 行业动态 更新时间:2024-06-14 16:57:40
维护和控制GUI状态和子状态(Maintain and control GUI states and substates) java

我正在创建一个图形阅读器程序,该程序将采取任何扫描图形,并将其值转换为CSV,不费吹灰之力。 下图描述了基本的控制流程

我有一个满足基本要求的原型,但在开始开发之前,我想知道维护GUI状态和子状态的最佳方法。 现在我使用枚举:

public enum UIState { MAKING_SELECTION, SELECTING_AXIS_POINTS, SETTING_VALUES, SELECTING_GRAPH_POINTS }

控制器有一个UIState ,可以通过调用按钮和鼠标侦听器来设置

public void setUiState(UIState uiState) { switch (this.uiState = uiState) { case MAKING_SELECTION: frame.setCursor(new Cursor(Cursor.DEFAULT_CURSOR)); break; case SELECTING_AXIS_POINTS: clearSelection(); frame.setCursor(new Cursor(Cursor.CROSSHAIR_CURSOR)); break; case SETTING_VALUES: clearSelection(); break; case SELECTING_GRAPH_POINTS: frame.setCursor(new Cursor(Cursor.CROSSHAIR_CURSOR)); clearSelection(); break; } updateView(); //Repaints frame setChanged(); notifyObservers(uiState); }

我的OptionsPanel(包含所有按钮和输入字段的面板)观察控制器,并在观察到更改时调用巨大的开关:

@Override public void update(Observable o, Object arg) { if (arg instanceof UIState) { switch ((UIState)arg) { case MAKING_SELECTION: //Set component statuses break; case SELECTING_AXIS_POINTS: //Set component statuses break; case SETTING_VALUES: //Set component statuses break; case SELECTING_GRAPH_POINTS: //Set component statuses break; } } }

只需在我的每个按钮和文本字段上调用setEnabled()就可以完成组件的设置,而这些字段已经在少量组件中变得不清楚。 除了isLeftMouseButton()和isRightMouseButton()查询之外,我的鼠标侦听器也具有类似的开关,这些查询使整个事情变得非常混乱。

我的实现甚至不包括子状态,尽管我现在有点工作,但已经与光标的设置不一致。

所以我的问题是:是否有更好的解决方案来维护这些GUI状态和子状态,并根据用户输入设置UI组件状态,特别是允许更容易实现更一致性的方案?

I'm looking to create a graph reader program that will take any scanned graph and convert it's values to a CSV with little effort. The following graph describes the basic control flow

I've got a prototype up and running that fulfills my basic requirements, but before proceeding with developement I want to know the best way to maintain GUI states and substates. Right now I'm using an enum:

public enum UIState { MAKING_SELECTION, SELECTING_AXIS_POINTS, SETTING_VALUES, SELECTING_GRAPH_POINTS }

The controller has one UIState that can be set by buttons and mouse listeners by calling

public void setUiState(UIState uiState) { switch (this.uiState = uiState) { case MAKING_SELECTION: frame.setCursor(new Cursor(Cursor.DEFAULT_CURSOR)); break; case SELECTING_AXIS_POINTS: clearSelection(); frame.setCursor(new Cursor(Cursor.CROSSHAIR_CURSOR)); break; case SETTING_VALUES: clearSelection(); break; case SELECTING_GRAPH_POINTS: frame.setCursor(new Cursor(Cursor.CROSSHAIR_CURSOR)); clearSelection(); break; } updateView(); //Repaints frame setChanged(); notifyObservers(uiState); }

My OptionsPanel, the panel that contains all buttons and input fields, observes the controller and calls a huge switch if it observes change:

@Override public void update(Observable o, Object arg) { if (arg instanceof UIState) { switch ((UIState)arg) { case MAKING_SELECTION: //Set component statuses break; case SELECTING_AXIS_POINTS: //Set component statuses break; case SETTING_VALUES: //Set component statuses break; case SELECTING_GRAPH_POINTS: //Set component statuses break; } } }

The setting of the components is done just by calling setEnabled() on every single one of my buttons and text fields which becomes unclear already with a small amount of components. My mouse listeners also have similar switches in addition to the isLeftMouseButton() and isRightMouseButton() queries which make the whole thing really confusing.

My implementation doesn't even include substates and even though I've kinda got it working right now, there already is inconsistency with the setting of the cursor.

So my question is: Is there a better solution to maintaining those GUI states and substates and set the UI components status based on user input, especially one that allows for more consistency easier?

更多推荐

本文发布于:2023-04-13 12:47:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/dzcp/e4330c90b5fb7373c196766b1e19dc8f.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:状态   Maintain   GUI   substates   states

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!