gdx-studio

#libgdx#java#desktop

git clone https://git.pyrossh.dev/gdx-studio

An IDE for creating Games using libgdx and Java supported on all platforms Android, iOS, Desktop


src/gdxstudio/panel/OptionsPanel.java
a9b2a64 1
package gdxstudio.panel;
a9b2a64 2
import gdxstudio.Content;
a9b2a64 3
import gdxstudio.Editor;
a9b2a64 4
import gdxstudio.Frame;
a9b2a64 5
import gdxstudio.Icon;
a9b2a64 6
import gdxstudio.Style;
a9b2a64 7
a62d533 8
import java.awt.Component;
a62d533 9
import java.awt.Font;
a62d533 10
import java.awt.event.ActionEvent;
a62d533 11
import java.awt.event.ActionListener;
a62d533 12
a62d533 13
import javax.swing.BorderFactory;
a62d533 14
import javax.swing.JComboBox;
a62d533 15
import javax.swing.JLabel;
a62d533 16
import javax.swing.JPanel;
a9b2a64 17
import javax.swing.JToggleButton;
a62d533 18
import javax.swing.SpringLayout;
a9b2a64 19
import javax.swing.SwingConstants;
a62d533 20
a62d533 21
import web.laf.lite.layout.HorizontalFlowLayout;
a62d533 22
import web.laf.lite.layout.ToolbarLayout;
a62d533 23
import web.laf.lite.layout.VerticalFlowLayout;
a62d533 24
import web.laf.lite.popup.AlignPanel;
a62d533 25
import web.laf.lite.utils.SpringUtils;
7c84877 26
import web.laf.lite.utils.UIUtils;
a9b2a64 27
import web.laf.lite.widget.Register;
a9b2a64 28
import web.laf.lite.widget.WebButtonGroup;
a62d533 29
import web.laf.lite.widget.WebSwitch;
a62d533 30
a62d533 31
public class OptionsPanel extends JPanel implements ActionListener {
a62d533 32
	private static final long serialVersionUID = 1L;
a62d533 33
	JPanel row1 = new JPanel(new HorizontalFlowLayout());
a62d533 34
	
a62d533 35
	JPanel content1 = new JPanel(new VerticalFlowLayout());
a62d533 36
	JPanel content2 = new JPanel(new VerticalFlowLayout());
a62d533 37
	
7c84877 38
	JPanel conten34Border = new JPanel(new VerticalFlowLayout());
a62d533 39
	JPanel content34 = new JPanel(new HorizontalFlowLayout());
a62d533 40
	JPanel content3 = new JPanel(new VerticalFlowLayout());
a62d533 41
	JPanel content4 = new JPanel(new VerticalFlowLayout());
7c84877 42
	
7c84877 43
	JPanel conten5Border = new JPanel(new VerticalFlowLayout());
a62d533 44
	JPanel content5 = new JPanel(new SpringLayout());
a62d533 45
a62d533 46
	public OptionsPanel(){
7c84877 47
		super(new VerticalFlowLayout(0, 10));
7c84877 48
		UIUtils.setUndecorated(this, true);
7c84877 49
		createHeader(content1, "ToolBar");
7c84877 50
		createHeader(content2, "SearchBar");
7c84877 51
		createHeader(conten34Border, "Editor");
7c84877 52
		createHeader(conten5Border, "Texture Packer");
a62d533 53
        WebSwitch left = new WebSwitch(); 
a62d533 54
        WebSwitch right = new WebSwitch();
a62d533 55
        WebSwitch status = new WebSwitch();
a62d533 56
        menuItem(content1, left, "Show Left SideBar");
a62d533 57
        menuItem(content1, right, "Show Right SideBar");
a62d533 58
        menuItem(content1, status, "Show StatusBar");
a62d533 59
        row1.add(content1);
9b56888 60
        /*
9b56888 61
         *  Rewrite this with first launch
9b56888 62
         */
9b56888 63
        //if(!left.load()) Frame.toggleLeftSideBar();
9b56888 64
        //if(!right.load()) Frame.toggleRightSideBar();
9b56888 65
        //if(!status.load()) Frame.toggleStatusBar();
a62d533 66
        left.addActionListener(new ActionListener(){
a62d533 67
     		@Override
a62d533 68
     		public void actionPerformed(ActionEvent arg0) {
a62d533 69
     			Frame.toggleLeftSideBar();
a62d533 70
     		}
a62d533 71
        });
a62d533 72
        right.addActionListener(new ActionListener(){
a62d533 73
     		@Override
a62d533 74
     		public void actionPerformed(ActionEvent arg0) {
a62d533 75
     			Frame.toggleRightSideBar();
a62d533 76
     		}
a62d533 77
        });
a62d533 78
        status.addActionListener(new ActionListener(){
a62d533 79
     		@Override
a62d533 80
     		public void actionPerformed(ActionEvent arg0) {
a62d533 81
     			Frame.toggleStatusBar();
a62d533 82
     		}
a62d533 83
        });
a62d533 84
        
a62d533 85
        // Search Stuff
a62d533 86
        final WebSwitch cs = new WebSwitch(); 
a62d533 87
        final WebSwitch ww = new WebSwitch();
a62d533 88
        final WebSwitch re = new WebSwitch();
a62d533 89
        menuItem(content2, cs, "Case Sensitive");
a62d533 90
        menuItem(content2,ww, "Whole Word");
a62d533 91
        menuItem(content2,re, "Regular Expression");
a62d533 92
        row1.add(content2);
a62d533 93
        
a62d533 94
        cs.addActionListener(new ActionListener(){
a62d533 95
			@Override
a62d533 96
			public void actionPerformed(ActionEvent arg0) {
a62d533 97
				Editor.context.setMatchCase(cs.isSelected());
a62d533 98
			}
a62d533 99
        });
a62d533 100
        
a62d533 101
        ww.addActionListener(new ActionListener(){
a62d533 102
			@Override
a62d533 103
			public void actionPerformed(ActionEvent arg0) {
a62d533 104
				Editor.context.setWholeWord(ww.isSelected());
a62d533 105
			}
a62d533 106
        });
a62d533 107
        
a62d533 108
        re.addActionListener(new ActionListener(){
a62d533 109
			@Override
a62d533 110
			public void actionPerformed(ActionEvent arg0) {
a62d533 111
				Editor.context.setRegularExpression(re.isSelected());
a62d533 112
			}
a62d533 113
        });
a62d533 114
  
a62d533 115
        // Editor Stuff
a62d533 116
        final WebSwitch showLineNumbers = new WebSwitch();
a62d533 117
        final WebSwitch showMargin = new WebSwitch();
a62d533 118
        final WebSwitch codeFold = new WebSwitch();
a62d533 119
        final WebSwitch showEol = new WebSwitch();
a62d533 120
        final WebSwitch paintTabLines = new WebSwitch();
a62d533 121
        final WebSwitch showWhitespaces = new WebSwitch();
a62d533 122
        //final JSlider tabSlider = new JSlider(0, 0, 0l
a62d533 123
        menuItem(content3,showLineNumbers, "Show Line Numbers");
a62d533 124
        menuItem(content3,showMargin, "Show Margin");
a62d533 125
        menuItem(content3,showEol, "Show Eol");
a62d533 126
        content34.add(content3);
a62d533 127
      
a62d533 128
        
a62d533 129
        menuItem(content4,paintTabLines, "Show Tab");
a62d533 130
        menuItem(content4,codeFold, "Code Folding");
a62d533 131
        menuItem(content4,showWhitespaces, "Show WhiteSpace");
a62d533 132
        content34.add(content4);
a62d533 133
        add(row1);
7c84877 134
        conten34Border.add(content34);
7c84877 135
        add(conten34Border);
a62d533 136
        
a62d533 137
    	createRow(content5, "Encoding Format", new JComboBox<String>(new String[]{"RGBA8888", "RGBA4444", "RGB888", "RGB565", 
a62d533 138
    			"Alpha", "LuminanceAlpha", "Intensity"}));
a62d533 139
    	createRow(content5, "Min Filter",  new JComboBox<String>(new String[]{"Nearest", "Linear", "MipMap", "MipMapNearestNearest",
a62d533 140
    			"MipMapNearestLinear", "MipMapLinearNearest", "MipMapLinearLinear"}));
a62d533 141
    	createRow(content5, "Output Format", new JComboBox<String>(new String[]{"Nearest", "Linear", "MipMap", "MipMapNearestNearest", "MipMapNearestLinear", "MipMapLinearNearest", "MipMapLinearLinear"}));
a62d533 142
    	createRow(content5, "Mag Filter", new JComboBox<String>(new String[]{"png", "jpg"}));
a62d533 143
    	
a62d533 144
    	JComboBox<String> wcb1 = new JComboBox<String>();
a62d533 145
    	for(int i= 0; i <= 10; i++)
a62d533 146
    			wcb1.addItem(""+(2<<i));
a62d533 147
    	createRow(content5, "Min Page Width", wcb1);
a62d533 148
    	createRow(content5, "PaddingX", new JComboBox<String>());
a62d533 149
    	JComboBox<String> wcb2 = new JComboBox<String>();
a62d533 150
    	for(int i= 0; i <= 10; i++)
a62d533 151
    			wcb2.addItem(""+(2<<i));
a62d533 152
    	createRow(content5, "Min Page Height", wcb2);
a62d533 153
    	createRow(content5, "PaddingY", new JComboBox<String>());
a62d533 154
    	
a62d533 155
    	JComboBox<String> wcb3 = new JComboBox<String>();
a62d533 156
    	for(int i= 0; i <= 10; i++)
a62d533 157
    			wcb3.addItem(""+(2<<i));
a62d533 158
    	createRow(content5, "Max Page Width", wcb3);
a62d533 159
    	createRow(content5, "ClampX", new JComboBox<String>());
a62d533 160
    	JComboBox<String> wcb4 = new JComboBox<String>();
a62d533 161
    	for(int i= 0; i <= 10; i++)
a62d533 162
    			wcb4.addItem(""+(2<<i));
a62d533 163
    	createRow(content5, "Max Page Height", wcb4);
a62d533 164
    	createRow(content5, "ClampY", new JComboBox<String>());
a62d533 165
    	
a62d533 166
    	SpringUtils.makeCompactGrid(content5, 6, 4, 10, 0, 10, 5);
7c84877 167
    	conten5Border.add(content5);
7c84877 168
    	add(conten5Border);
a9b2a64 169
        initStyle();
a62d533 170
       // add(menuItem(tabSlider, "Tab Size"));
a62d533 171
      //setMarginLineColor(Color.black);
a62d533 172
        //setMarkOccurrences(true);
a62d533 173
        //setPaintMarkOccurrencesBorder(true);
a62d533 174
        //setPaintMatchedBracketPair(true);
a62d533 175
        
a62d533 176
    	Content.editorScroll.setLineNumbersEnabled(showLineNumbers.isSelected());
a62d533 177
    	Content.editorScroll.setIconRowHeaderEnabled(showMargin.isSelected());
a62d533 178
        Content.editor.setCodeFoldingEnabled(codeFold.isSelected());
a62d533 179
        Content.editor.setPaintTabLines(paintTabLines.isSelected());
a62d533 180
    	Content.editor.setWhitespaceVisible(showWhitespaces.isSelected());
a62d533 181
    	Content.editor.setEOLMarkersVisible(showEol.isSelected());
a62d533 182
    	
a62d533 183
    	
a62d533 184
    	showLineNumbers.addActionListener(new ActionListener(){
a62d533 185
			@Override
a62d533 186
			public void actionPerformed(ActionEvent arg0) {
a62d533 187
				Content.editorScroll.setLineNumbersEnabled(showLineNumbers.isSelected());
a62d533 188
			}
a62d533 189
        });
a62d533 190
    	
a62d533 191
    	showMargin.addActionListener(new ActionListener(){
a62d533 192
			@Override
a62d533 193
			public void actionPerformed(ActionEvent arg0) {
a62d533 194
				Content.editorScroll.setIconRowHeaderEnabled(showMargin.isSelected());
a62d533 195
			}
a62d533 196
        });
a62d533 197
        
a62d533 198
        codeFold.addActionListener(new ActionListener(){
a62d533 199
			@Override
a62d533 200
			public void actionPerformed(ActionEvent arg0) {
a62d533 201
				Content.editor.setCodeFoldingEnabled(codeFold.isSelected());
a62d533 202
			}
a62d533 203
        });
a62d533 204
        showEol.addActionListener(new ActionListener(){
a62d533 205
			@Override
a62d533 206
			public void actionPerformed(ActionEvent arg0) {
a62d533 207
				Content.editor.setEOLMarkersVisible(showEol.isSelected());
a62d533 208
			}
a62d533 209
        });
a62d533 210
        paintTabLines.addActionListener(new ActionListener(){
a62d533 211
			@Override
a62d533 212
			public void actionPerformed(ActionEvent arg0) {
a62d533 213
				Content.editor.setPaintTabLines(paintTabLines.isSelected());
a62d533 214
			}
a62d533 215
        });
a62d533 216
        showWhitespaces.addActionListener(new ActionListener(){
a62d533 217
			@Override
a62d533 218
			public void actionPerformed(ActionEvent arg0) {
a62d533 219
				Content.editor.setWhitespaceVisible(showWhitespaces.isSelected());
a62d533 220
			}
a62d533 221
        }); 
a62d533 222
	}
a62d533 223
	
a62d533 224
	void createRow(JPanel content, String title, Component b){
a62d533 225
    	JLabel label = new JLabel(title);
a62d533 226
		label.setFont(label.getFont().deriveFont(Font.BOLD));
a62d533 227
		content.add(label);
a62d533 228
		if(b instanceof WebSwitch)
a62d533 229
			content.add(new AlignPanel(b, AlignPanel.LEFT, AlignPanel.VERTICAL));
a62d533 230
		else
a62d533 231
			content.add(b);
a62d533 232
    }
a62d533 233
	
a62d533 234
	void menuItem(JPanel content, final WebSwitch sw, String text){
a62d533 235
		final JLabel label = new JLabel("   "+text);
7c84877 236
		label.setFont(label.getFont().deriveFont(Font.BOLD));
a62d533 237
		JPanel pan = new JPanel(new ToolbarLayout());
a62d533 238
		pan.setOpaque(false);
a62d533 239
		pan.add(label, ToolbarLayout.START);
a62d533 240
		pan.add(sw, ToolbarLayout.END);
a62d533 241
		content.add(pan);
a62d533 242
	}
7c84877 243
	
7c84877 244
	void createHeader(JPanel content, String title){
7c84877 245
		content.add(new Style.TitleLabel(title));
7c84877 246
		content.setBorder(BorderFactory.createLineBorder(Style.border));
7c84877 247
	}
a9b2a64 248
	
a9b2a64 249
	void createHeader(JPanel content, String title, String icon){
a9b2a64 250
		content.add(new Style.TitleLabel(title, icon));
a9b2a64 251
		content.setBorder(BorderFactory.createLineBorder(Style.border));
a9b2a64 252
	}
a9b2a64 253
	
a9b2a64 254
	void initStyle(){
a9b2a64 255
		JPanel vert = new JPanel(new VerticalFlowLayout());
a9b2a64 256
		createHeader(vert, "Styles");
a9b2a64 257
        ThemeButton[] themeButtons = {
a9b2a64 258
        		createThemeItem("IntelliJ IDEA", "idea"),
a9b2a64 259
        		createThemeItem("Dark", "dark"),
a9b2a64 260
        		createThemeItem("Visual Studio", "vs"),
a9b2a64 261
        		createThemeItem("Eclipse", "eclipse")
a9b2a64 262
        };
a9b2a64 263
        WebButtonGroup themeGroup = new WebButtonGroup(WebButtonGroup.HORIZONTAL, true, themeButtons);
a9b2a64 264
        themeGroup.setButtonsDrawFocus(false);
a9b2a64 265
        themeGroup.setButtonsDrawFocus(false);
a9b2a64 266
        vert.add(themeGroup);
a9b2a64 267
        add(vert);
a9b2a64 268
	}
a9b2a64 269
	
a9b2a64 270
	ThemeButton createThemeItem(String title, String iconname){
a9b2a64 271
		final ThemeButton themeButton = new ThemeButton(title, iconname);
a9b2a64 272
		if(Register.getTheme().equals(iconname)) 
a9b2a64 273
			themeButton.setSelected(true);
a9b2a64 274
		themeButton .addActionListener (new ActionListener (){
a9b2a64 275
            public void actionPerformed (ActionEvent e){
a9b2a64 276
            	Register.setTheme(themeButton.iconame);
a9b2a64 277
            	Content.theme = Icon.loadTheme(themeButton.iconame);
a9b2a64 278
            	Content.theme.apply(Content.editor);
a9b2a64 279
           }
a9b2a64 280
        });
a9b2a64 281
		return themeButton;
a9b2a64 282
	}
a62d533 283
a62d533 284
	@Override
a62d533 285
	public void actionPerformed(ActionEvent e) {
a62d533 286
		setVisible(false);
a62d533 287
	}
a62d533 288
}
a9b2a64 289
a9b2a64 290
a9b2a64 291
final class ThemeButton extends JToggleButton{
a9b2a64 292
	private static final long serialVersionUID = 1L;
a9b2a64 293
	String iconame;
a9b2a64 294
	ThemeButton(String text, String ic){
a9b2a64 295
		super(text, Icon.icon(ic));
a9b2a64 296
		iconame = ic;
a9b2a64 297
		setVerticalTextPosition(SwingConstants.BOTTOM);
a9b2a64 298
        setHorizontalTextPosition(SwingConstants.CENTER);
a9b2a64 299
        setFocusable(false);
a9b2a64 300
	}
a9b2a64 301
}