annotate src/junotu/TabOptions.java @ 111:b93c6236c6cb

TabOptions: Minor progress
author Fox
date Thu, 15 Jun 2023 00:53:55 +0200
parents e4588b8a8ddc
children 9bf9fd26bb33
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
107
e4588b8a8ddc Started on TabOptions
Fox
parents:
diff changeset
1 package junotu;
e4588b8a8ddc Started on TabOptions
Fox
parents:
diff changeset
2
e4588b8a8ddc Started on TabOptions
Fox
parents:
diff changeset
3 import java.util.Vector;
e4588b8a8ddc Started on TabOptions
Fox
parents:
diff changeset
4
e4588b8a8ddc Started on TabOptions
Fox
parents:
diff changeset
5 import java.awt.Component;
e4588b8a8ddc Started on TabOptions
Fox
parents:
diff changeset
6 import javax.swing.JPanel;
e4588b8a8ddc Started on TabOptions
Fox
parents:
diff changeset
7 import javax.swing.Box;
e4588b8a8ddc Started on TabOptions
Fox
parents:
diff changeset
8 import javax.swing.JScrollPane;
e4588b8a8ddc Started on TabOptions
Fox
parents:
diff changeset
9 import javax.swing.JButton;
e4588b8a8ddc Started on TabOptions
Fox
parents:
diff changeset
10
e4588b8a8ddc Started on TabOptions
Fox
parents:
diff changeset
11 import java.awt.BorderLayout;
e4588b8a8ddc Started on TabOptions
Fox
parents:
diff changeset
12 import java.awt.FlowLayout;
e4588b8a8ddc Started on TabOptions
Fox
parents:
diff changeset
13 import javax.swing.BoxLayout;
e4588b8a8ddc Started on TabOptions
Fox
parents:
diff changeset
14
e4588b8a8ddc Started on TabOptions
Fox
parents:
diff changeset
15 import java.awt.event.ActionEvent;
e4588b8a8ddc Started on TabOptions
Fox
parents:
diff changeset
16 import java.awt.event.ActionListener;
e4588b8a8ddc Started on TabOptions
Fox
parents:
diff changeset
17
111
b93c6236c6cb TabOptions: Minor progress
Fox
parents: 107
diff changeset
18 import junotu.Main;
107
e4588b8a8ddc Started on TabOptions
Fox
parents:
diff changeset
19 import junotu.Window.TabInterface;
e4588b8a8ddc Started on TabOptions
Fox
parents:
diff changeset
20 import junotu.OptionTree;
111
b93c6236c6cb TabOptions: Minor progress
Fox
parents: 107
diff changeset
21 import junotu.Card;
107
e4588b8a8ddc Started on TabOptions
Fox
parents:
diff changeset
22
e4588b8a8ddc Started on TabOptions
Fox
parents:
diff changeset
23 public class TabOptions extends JPanel implements ActionListener, TabInterface {
e4588b8a8ddc Started on TabOptions
Fox
parents:
diff changeset
24
e4588b8a8ddc Started on TabOptions
Fox
parents:
diff changeset
25 private static final String ACTION_PATH_BUTTON = "path_button";
e4588b8a8ddc Started on TabOptions
Fox
parents:
diff changeset
26
e4588b8a8ddc Started on TabOptions
Fox
parents:
diff changeset
27 private static class Option extends JPanel implements ActionListener {
e4588b8a8ddc Started on TabOptions
Fox
parents:
diff changeset
28 TabOptions events;
e4588b8a8ddc Started on TabOptions
Fox
parents:
diff changeset
29
e4588b8a8ddc Started on TabOptions
Fox
parents:
diff changeset
30 @Override
e4588b8a8ddc Started on TabOptions
Fox
parents:
diff changeset
31 public void actionPerformed( ActionEvent e )
e4588b8a8ddc Started on TabOptions
Fox
parents:
diff changeset
32 {
e4588b8a8ddc Started on TabOptions
Fox
parents:
diff changeset
33 if( events != null ) {
e4588b8a8ddc Started on TabOptions
Fox
parents:
diff changeset
34 events.actionPerformed( new ActionEvent( this, e.getID(), e.getActionCommand(), e.getWhen(), e.getModifiers() ) );
e4588b8a8ddc Started on TabOptions
Fox
parents:
diff changeset
35 }
e4588b8a8ddc Started on TabOptions
Fox
parents:
diff changeset
36 }
e4588b8a8ddc Started on TabOptions
Fox
parents:
diff changeset
37 }
e4588b8a8ddc Started on TabOptions
Fox
parents:
diff changeset
38
e4588b8a8ddc Started on TabOptions
Fox
parents:
diff changeset
39 private static class OptionFolder extends Option {
e4588b8a8ddc Started on TabOptions
Fox
parents:
diff changeset
40
e4588b8a8ddc Started on TabOptions
Fox
parents:
diff changeset
41 OptionTree.OptionFolder folder;
e4588b8a8ddc Started on TabOptions
Fox
parents:
diff changeset
42
e4588b8a8ddc Started on TabOptions
Fox
parents:
diff changeset
43 public OptionFolder( TabOptions events_, OptionTree.OptionFolder folder_ )
e4588b8a8ddc Started on TabOptions
Fox
parents:
diff changeset
44 {
e4588b8a8ddc Started on TabOptions
Fox
parents:
diff changeset
45 setLayout( new BoxLayout( this, BoxLayout.X_AXIS ) );
e4588b8a8ddc Started on TabOptions
Fox
parents:
diff changeset
46 events = events_;
e4588b8a8ddc Started on TabOptions
Fox
parents:
diff changeset
47 folder = folder_;
111
b93c6236c6cb TabOptions: Minor progress
Fox
parents: 107
diff changeset
48
107
e4588b8a8ddc Started on TabOptions
Fox
parents:
diff changeset
49 JButton button = new JButton( folder.brief );
111
b93c6236c6cb TabOptions: Minor progress
Fox
parents: 107
diff changeset
50
107
e4588b8a8ddc Started on TabOptions
Fox
parents:
diff changeset
51 this.add(button);
111
b93c6236c6cb TabOptions: Minor progress
Fox
parents: 107
diff changeset
52
107
e4588b8a8ddc Started on TabOptions
Fox
parents:
diff changeset
53 if( folder.hint.length() > 0 ) {
e4588b8a8ddc Started on TabOptions
Fox
parents:
diff changeset
54 button.setToolTipText( folder.hint );
e4588b8a8ddc Started on TabOptions
Fox
parents:
diff changeset
55 }
111
b93c6236c6cb TabOptions: Minor progress
Fox
parents: 107
diff changeset
56
107
e4588b8a8ddc Started on TabOptions
Fox
parents:
diff changeset
57 button.addActionListener(this);
e4588b8a8ddc Started on TabOptions
Fox
parents:
diff changeset
58 }
e4588b8a8ddc Started on TabOptions
Fox
parents:
diff changeset
59 }
e4588b8a8ddc Started on TabOptions
Fox
parents:
diff changeset
60 private static class OptionCategory extends Option {}
e4588b8a8ddc Started on TabOptions
Fox
parents:
diff changeset
61 private static class OptionCheckbox extends Option {}
e4588b8a8ddc Started on TabOptions
Fox
parents:
diff changeset
62 private static class OptionSlider extends Option {}
e4588b8a8ddc Started on TabOptions
Fox
parents:
diff changeset
63 private static class OptionNumberCounter extends Option {}
e4588b8a8ddc Started on TabOptions
Fox
parents:
diff changeset
64 private static class OptionString extends Option {}
e4588b8a8ddc Started on TabOptions
Fox
parents:
diff changeset
65 private static class OptionAction extends Option {}
e4588b8a8ddc Started on TabOptions
Fox
parents:
diff changeset
66
e4588b8a8ddc Started on TabOptions
Fox
parents:
diff changeset
67 static public final OptionTree OPTION_TREE;
e4588b8a8ddc Started on TabOptions
Fox
parents:
diff changeset
68 static {
e4588b8a8ddc Started on TabOptions
Fox
parents:
diff changeset
69 OPTION_TREE = new OptionTree();
111
b93c6236c6cb TabOptions: Minor progress
Fox
parents: 107
diff changeset
70 OPTION_TREE.root = new OptionTree.OptionFolder( Main.PROGRAM_NAME, Main.PROGRAM_NAME+" options." );
b93c6236c6cb TabOptions: Minor progress
Fox
parents: 107
diff changeset
71
107
e4588b8a8ddc Started on TabOptions
Fox
parents:
diff changeset
72 OptionTree.OptionFolder f1 = OPTION_TREE.add( new OptionTree.OptionFolder( "1", "Folder one." ) );
e4588b8a8ddc Started on TabOptions
Fox
parents:
diff changeset
73 OptionTree.OptionFolder f2 = OPTION_TREE.add( new OptionTree.OptionFolder( "2", "Folder two." ) );
e4588b8a8ddc Started on TabOptions
Fox
parents:
diff changeset
74 OptionTree.OptionFolder f3 = OPTION_TREE.add( new OptionTree.OptionFolder( "3", "Folder three." ) );
111
b93c6236c6cb TabOptions: Minor progress
Fox
parents: 107
diff changeset
75 OptionTree.OptionFolder developer = OPTION_TREE.add( new OptionTree.OptionFolder(
b93c6236c6cb TabOptions: Minor progress
Fox
parents: 107
diff changeset
76 "Development / Internal",
b93c6236c6cb TabOptions: Minor progress
Fox
parents: 107
diff changeset
77 "Development-related options. Be careful, those options were not designed with safety or intutiveness in mind. "+
b93c6236c6cb TabOptions: Minor progress
Fox
parents: 107
diff changeset
78 "Misusing them could corrupt your card database."
b93c6236c6cb TabOptions: Minor progress
Fox
parents: 107
diff changeset
79 ) );
b93c6236c6cb TabOptions: Minor progress
Fox
parents: 107
diff changeset
80
107
e4588b8a8ddc Started on TabOptions
Fox
parents:
diff changeset
81 f1.add( new OptionTree.OptionFolder( "1.1", "Folder one one." ) );
e4588b8a8ddc Started on TabOptions
Fox
parents:
diff changeset
82 f1.add( new OptionTree.OptionFolder( "1.2", "Folder one two." ) );
e4588b8a8ddc Started on TabOptions
Fox
parents:
diff changeset
83 f1.add( new OptionTree.OptionFolder( "1.3", "Folder one three." ) );
e4588b8a8ddc Started on TabOptions
Fox
parents:
diff changeset
84
e4588b8a8ddc Started on TabOptions
Fox
parents:
diff changeset
85 f2.add( new OptionTree.OptionFolder( "2.1", "Folder two one." ) );
e4588b8a8ddc Started on TabOptions
Fox
parents:
diff changeset
86 f2.add( new OptionTree.OptionFolder( "2.2", "Folder two two." ) );
e4588b8a8ddc Started on TabOptions
Fox
parents:
diff changeset
87 f2.add( new OptionTree.OptionFolder( "2.3", "Folder two three." ) );
e4588b8a8ddc Started on TabOptions
Fox
parents:
diff changeset
88
e4588b8a8ddc Started on TabOptions
Fox
parents:
diff changeset
89 f3.add( new OptionTree.OptionFolder( "3.1", "Folder three one." ) );
e4588b8a8ddc Started on TabOptions
Fox
parents:
diff changeset
90 f3.add( new OptionTree.OptionFolder( "3.2", "Folder three two." ) );
e4588b8a8ddc Started on TabOptions
Fox
parents:
diff changeset
91 f3.add( new OptionTree.OptionFolder( "3.3", "Folder three three." ) );
111
b93c6236c6cb TabOptions: Minor progress
Fox
parents: 107
diff changeset
92
b93c6236c6cb TabOptions: Minor progress
Fox
parents: 107
diff changeset
93 developer.add( new OptionTree.OptionCheckbox(
b93c6236c6cb TabOptions: Minor progress
Fox
parents: 107
diff changeset
94 Card.TAG_OPTION_PREFIX+"show_internal_tags",
b93c6236c6cb TabOptions: Minor progress
Fox
parents: 107
diff changeset
95 "Show 'internal' tags.",
b93c6236c6cb TabOptions: Minor progress
Fox
parents: 107
diff changeset
96 "Show tags prefixed with '_', which are normally hidden.",
b93c6236c6cb TabOptions: Minor progress
Fox
parents: 107
diff changeset
97 false
b93c6236c6cb TabOptions: Minor progress
Fox
parents: 107
diff changeset
98 ) );
b93c6236c6cb TabOptions: Minor progress
Fox
parents: 107
diff changeset
99
b93c6236c6cb TabOptions: Minor progress
Fox
parents: 107
diff changeset
100 developer.add( new OptionTree.OptionCategory( "Actions", "" ) );
b93c6236c6cb TabOptions: Minor progress
Fox
parents: 107
diff changeset
101
b93c6236c6cb TabOptions: Minor progress
Fox
parents: 107
diff changeset
102 developer.add( new OptionTree.OptionAction(
b93c6236c6cb TabOptions: Minor progress
Fox
parents: 107
diff changeset
103 "Resave all cards",
b93c6236c6cb TabOptions: Minor progress
Fox
parents: 107
diff changeset
104 "Go over the whole card database, load each card and save each card. "+
b93c6236c6cb TabOptions: Minor progress
Fox
parents: 107
diff changeset
105 "Does not update user edit timestamp, meaning card ordering should not change on the search page. "+
b93c6236c6cb TabOptions: Minor progress
Fox
parents: 107
diff changeset
106 "This might be a useful thing to run after changing "+Main.PROGRAM_NAME+" version (updating or downgrading)."
b93c6236c6cb TabOptions: Minor progress
Fox
parents: 107
diff changeset
107 ) );
b93c6236c6cb TabOptions: Minor progress
Fox
parents: 107
diff changeset
108
107
e4588b8a8ddc Started on TabOptions
Fox
parents:
diff changeset
109 }
e4588b8a8ddc Started on TabOptions
Fox
parents:
diff changeset
110
e4588b8a8ddc Started on TabOptions
Fox
parents:
diff changeset
111 public Card card;
e4588b8a8ddc Started on TabOptions
Fox
parents:
diff changeset
112 public Vector<OptionTree.OptionFolder> path = new Vector<OptionTree.OptionFolder>();
e4588b8a8ddc Started on TabOptions
Fox
parents:
diff changeset
113
e4588b8a8ddc Started on TabOptions
Fox
parents:
diff changeset
114 JPanel pathBox;
e4588b8a8ddc Started on TabOptions
Fox
parents:
diff changeset
115 Box optionList;
e4588b8a8ddc Started on TabOptions
Fox
parents:
diff changeset
116
e4588b8a8ddc Started on TabOptions
Fox
parents:
diff changeset
117 public TabOptions()
e4588b8a8ddc Started on TabOptions
Fox
parents:
diff changeset
118 {
e4588b8a8ddc Started on TabOptions
Fox
parents:
diff changeset
119 setLayout( new BorderLayout() );
e4588b8a8ddc Started on TabOptions
Fox
parents:
diff changeset
120 pathBox = new JPanel();
e4588b8a8ddc Started on TabOptions
Fox
parents:
diff changeset
121 optionList = Box.createVerticalBox();
e4588b8a8ddc Started on TabOptions
Fox
parents:
diff changeset
122 JScrollPane scroll = new JScrollPane(optionList);
e4588b8a8ddc Started on TabOptions
Fox
parents:
diff changeset
123 JButton apply = new JButton("Apply");
111
b93c6236c6cb TabOptions: Minor progress
Fox
parents: 107
diff changeset
124
107
e4588b8a8ddc Started on TabOptions
Fox
parents:
diff changeset
125 pathBox.setLayout( new FlowLayout( FlowLayout.LEFT ) );
111
b93c6236c6cb TabOptions: Minor progress
Fox
parents: 107
diff changeset
126
107
e4588b8a8ddc Started on TabOptions
Fox
parents:
diff changeset
127 add( pathBox, BorderLayout.NORTH );
e4588b8a8ddc Started on TabOptions
Fox
parents:
diff changeset
128 add( scroll, BorderLayout.CENTER );
e4588b8a8ddc Started on TabOptions
Fox
parents:
diff changeset
129 add( apply, BorderLayout.SOUTH );
111
b93c6236c6cb TabOptions: Minor progress
Fox
parents: 107
diff changeset
130
107
e4588b8a8ddc Started on TabOptions
Fox
parents:
diff changeset
131 path.add( OPTION_TREE.root );
111
b93c6236c6cb TabOptions: Minor progress
Fox
parents: 107
diff changeset
132
107
e4588b8a8ddc Started on TabOptions
Fox
parents:
diff changeset
133 scroll.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
e4588b8a8ddc Started on TabOptions
Fox
parents:
diff changeset
134
e4588b8a8ddc Started on TabOptions
Fox
parents:
diff changeset
135 }
e4588b8a8ddc Started on TabOptions
Fox
parents:
diff changeset
136
e4588b8a8ddc Started on TabOptions
Fox
parents:
diff changeset
137 @Override
e4588b8a8ddc Started on TabOptions
Fox
parents:
diff changeset
138 public void onSwitchedTo()
e4588b8a8ddc Started on TabOptions
Fox
parents:
diff changeset
139 {
e4588b8a8ddc Started on TabOptions
Fox
parents:
diff changeset
140 generate();
e4588b8a8ddc Started on TabOptions
Fox
parents:
diff changeset
141 }
e4588b8a8ddc Started on TabOptions
Fox
parents:
diff changeset
142
e4588b8a8ddc Started on TabOptions
Fox
parents:
diff changeset
143 public void generate()
e4588b8a8ddc Started on TabOptions
Fox
parents:
diff changeset
144 {
e4588b8a8ddc Started on TabOptions
Fox
parents:
diff changeset
145 optionList.removeAll();
e4588b8a8ddc Started on TabOptions
Fox
parents:
diff changeset
146 pathBox.removeAll();
e4588b8a8ddc Started on TabOptions
Fox
parents:
diff changeset
147 OptionTree.OptionFolder page = path.get( path.size()-1 );
e4588b8a8ddc Started on TabOptions
Fox
parents:
diff changeset
148 for( int i = 0; i < page.options.size(); i++ ) {
e4588b8a8ddc Started on TabOptions
Fox
parents:
diff changeset
149 OptionTree.Option<?> option = page.options.get(i);
e4588b8a8ddc Started on TabOptions
Fox
parents:
diff changeset
150 if( option instanceof OptionTree.OptionFolder ) {
e4588b8a8ddc Started on TabOptions
Fox
parents:
diff changeset
151 optionList.add( new OptionFolder( this, (OptionTree.OptionFolder)option ) );
e4588b8a8ddc Started on TabOptions
Fox
parents:
diff changeset
152 } else {
e4588b8a8ddc Started on TabOptions
Fox
parents:
diff changeset
153 System.out.print( "TabOptions, generate: Unknown option type '"+option.getClass().getName()+"', cannot create interface.\n" );
e4588b8a8ddc Started on TabOptions
Fox
parents:
diff changeset
154 }
e4588b8a8ddc Started on TabOptions
Fox
parents:
diff changeset
155 }
e4588b8a8ddc Started on TabOptions
Fox
parents:
diff changeset
156 optionList.add( Box.createVerticalGlue() );
e4588b8a8ddc Started on TabOptions
Fox
parents:
diff changeset
157 for( int i = 0; i < path.size(); i++ ) {
e4588b8a8ddc Started on TabOptions
Fox
parents:
diff changeset
158 JButton button = new JButton( path.get(i).brief );
e4588b8a8ddc Started on TabOptions
Fox
parents:
diff changeset
159 pathBox.add( button );
e4588b8a8ddc Started on TabOptions
Fox
parents:
diff changeset
160 button.setActionCommand( ACTION_PATH_BUTTON );
e4588b8a8ddc Started on TabOptions
Fox
parents:
diff changeset
161 button.addActionListener(this);
111
b93c6236c6cb TabOptions: Minor progress
Fox
parents: 107
diff changeset
162 if( path.get(i).hint.length() > 0 ) {
b93c6236c6cb TabOptions: Minor progress
Fox
parents: 107
diff changeset
163 button.setToolTipText( path.get(i).hint );
b93c6236c6cb TabOptions: Minor progress
Fox
parents: 107
diff changeset
164 }
107
e4588b8a8ddc Started on TabOptions
Fox
parents:
diff changeset
165 }
e4588b8a8ddc Started on TabOptions
Fox
parents:
diff changeset
166 pathBox.add( Box.createHorizontalGlue() );
e4588b8a8ddc Started on TabOptions
Fox
parents:
diff changeset
167
e4588b8a8ddc Started on TabOptions
Fox
parents:
diff changeset
168 revalidate();
e4588b8a8ddc Started on TabOptions
Fox
parents:
diff changeset
169 repaint();
e4588b8a8ddc Started on TabOptions
Fox
parents:
diff changeset
170 }
e4588b8a8ddc Started on TabOptions
Fox
parents:
diff changeset
171
e4588b8a8ddc Started on TabOptions
Fox
parents:
diff changeset
172 public void actionPerformed( ActionEvent e )
e4588b8a8ddc Started on TabOptions
Fox
parents:
diff changeset
173 {
e4588b8a8ddc Started on TabOptions
Fox
parents:
diff changeset
174 Object source = e.getSource();
e4588b8a8ddc Started on TabOptions
Fox
parents:
diff changeset
175 String command = e.getActionCommand();
e4588b8a8ddc Started on TabOptions
Fox
parents:
diff changeset
176
e4588b8a8ddc Started on TabOptions
Fox
parents:
diff changeset
177 switch( command ) {
e4588b8a8ddc Started on TabOptions
Fox
parents:
diff changeset
178 case ACTION_PATH_BUTTON: {
e4588b8a8ddc Started on TabOptions
Fox
parents:
diff changeset
179 Component[] buttons = pathBox.getComponents();
e4588b8a8ddc Started on TabOptions
Fox
parents:
diff changeset
180 for( int i = 0; i < buttons.length; i++ ) {
e4588b8a8ddc Started on TabOptions
Fox
parents:
diff changeset
181 if( buttons[i] == source ) {
e4588b8a8ddc Started on TabOptions
Fox
parents:
diff changeset
182 path.setSize( i+1 );
e4588b8a8ddc Started on TabOptions
Fox
parents:
diff changeset
183 generate();
e4588b8a8ddc Started on TabOptions
Fox
parents:
diff changeset
184 return;
e4588b8a8ddc Started on TabOptions
Fox
parents:
diff changeset
185 }
e4588b8a8ddc Started on TabOptions
Fox
parents:
diff changeset
186 }
e4588b8a8ddc Started on TabOptions
Fox
parents:
diff changeset
187 }
e4588b8a8ddc Started on TabOptions
Fox
parents:
diff changeset
188 }
e4588b8a8ddc Started on TabOptions
Fox
parents:
diff changeset
189
e4588b8a8ddc Started on TabOptions
Fox
parents:
diff changeset
190 if( source instanceof OptionFolder ) {
e4588b8a8ddc Started on TabOptions
Fox
parents:
diff changeset
191 OptionFolder clicked = (OptionFolder)source;
e4588b8a8ddc Started on TabOptions
Fox
parents:
diff changeset
192 path.add( clicked.folder );
e4588b8a8ddc Started on TabOptions
Fox
parents:
diff changeset
193 generate();
e4588b8a8ddc Started on TabOptions
Fox
parents:
diff changeset
194 }
e4588b8a8ddc Started on TabOptions
Fox
parents:
diff changeset
195 }
e4588b8a8ddc Started on TabOptions
Fox
parents:
diff changeset
196
e4588b8a8ddc Started on TabOptions
Fox
parents:
diff changeset
197 }