Skip to content

Commit

Permalink
替换文本框为滑块
Browse files Browse the repository at this point in the history
  • Loading branch information
SinarPandora committed Mar 25, 2020
1 parent 5acb4cf commit 6ce1af7
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 50 deletions.
51 changes: 35 additions & 16 deletions src/com/jiyuanime/ui/Setting.form
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,6 @@
<grid row="0" column="3" row-span="1" col-span="1" vsize-policy="1" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
</hspacer>
<component id="2a2d7" class="javax.swing.JTextField" binding="particleMaxCountTextField">
<constraints>
<grid row="0" column="1" row-span="1" col-span="2" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
<preferred-size width="150" height="-1"/>
</grid>
</constraints>
<properties>
<text value=""/>
</properties>
</component>
<component id="bc61a" class="javax.swing.JLabel">
<constraints>
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
Expand Down Expand Up @@ -74,15 +64,44 @@
<text value="particle size"/>
</properties>
</component>
<component id="9e889" class="javax.swing.JTextField" binding="particleSizeTextField">
<component id="e816c" class="javax.swing.JSlider" binding="particleSizeSlider">
<constraints>
<grid row="2" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<maximum value="20"/>
<minimum value="1"/>
<paintLabels value="true"/>
<paintTicks value="false"/>
<value value="6"/>
<valueIsAdjusting value="true"/>
</properties>
</component>
<component id="d3ebe" class="javax.swing.JSlider" binding="particleMaxCountSlider">
<constraints>
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<maximum value="30"/>
<minimum value="1"/>
<paintLabels value="true"/>
<value value="5"/>
</properties>
</component>
<component id="dbb7c" class="javax.swing.JLabel" binding="maxCountValue">
<constraints>
<grid row="0" column="2" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="0"/>
</properties>
</component>
<component id="fc191" class="javax.swing.JLabel" binding="sizeValue">
<constraints>
<grid row="2" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
<preferred-size width="150" height="-1"/>
</grid>
<grid row="2" column="2" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<enabled value="true"/>
<text value=""/>
<text value="0"/>
</properties>
</component>
</children>
Expand Down
60 changes: 26 additions & 34 deletions src/com/jiyuanime/ui/Setting.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,13 @@

public class Setting implements Configurable {

private JTextField particleMaxCountTextField;
private ColorPanel colorChooser;
private JPanel rootPanel;
private JCheckBox colorAutoCheckBox;
private JTextField particleSizeTextField;
private JSlider particleSizeSlider;
private JSlider particleMaxCountSlider;
private JLabel maxCountValue;
private JLabel sizeValue;

private Config.State state = Config.getInstance().state;

Expand All @@ -29,69 +31,59 @@ public String getDisplayName() {
@Nullable
@Override
public JComponent createComponent() {

initListener();

initSetting();

return this.rootPanel;
}

@Override
public boolean isModified() {

try {
return !Comparing.equal(state.PARTICLE_MAX_COUNT, Integer.parseInt(particleMaxCountTextField.getText())) ||
!Comparing.equal(state.PARTICLE_SIZE, Integer.parseInt(particleSizeTextField.getText())) ||
return !Comparing.equal(state.PARTICLE_MAX_COUNT, particleMaxCountSlider.getValue()) ||
!Comparing.equal(state.PARTICLE_SIZE, particleSizeSlider.getValue()) ||
!Comparing.equal(state.PARTICLE_COLOR, colorAutoCheckBox.isSelected() ? null : colorChooser.getSelectedColor());
} catch (NumberFormatException $ex) {
return true;
}

}

@Override
public void apply() throws ConfigurationException {

try {
int particleMaxCount = Integer.parseInt(particleMaxCountTextField.getText());
if(particleMaxCount <= 0) {
throw new ConfigurationException("The 'particle max count' field must be greater than 0");
}
state.PARTICLE_MAX_COUNT = particleMaxCount;
} catch (NumberFormatException $ex) {
throw new ConfigurationException("The 'particle max count' field format error.");
}

try {
int particleSize = Integer.parseInt(particleSizeTextField.getText());
if(particleSize <= 0) {
throw new ConfigurationException("The 'particle size' field must be greater than 0");
}
state.PARTICLE_SIZE = particleSize;
} catch (NumberFormatException $ex) {
throw new ConfigurationException("The 'particle size' field format error.");
}

state.PARTICLE_MAX_COUNT = particleMaxCountSlider.getValue();
state.PARTICLE_SIZE = particleSizeSlider.getValue();
if(!colorAutoCheckBox.isSelected() && colorChooser.getSelectedColor() == null) {
throw new ConfigurationException("'particle color' is not choose.'");
}

state.PARTICLE_COLOR = colorAutoCheckBox.isSelected() ? null : colorChooser.getSelectedColor();
}

@Override
public void reset() {
this.initSetting();
}

private void initListener() {
colorAutoCheckBox.addItemListener(event -> {
JCheckBox item = (JCheckBox) event.getItem();

colorChooser.setSelectedColor(null);
colorChooser.setEditable(!item.isSelected());
});
particleSizeSlider.addChangeListener(event -> {
JSlider source = (JSlider) event.getSource();
sizeValue.setText(String.valueOf(source.getValue()));
});
particleMaxCountSlider.addChangeListener(event -> {
JSlider source = (JSlider) event.getSource();
maxCountValue.setText(String.valueOf(source.getValue()));
});
}

private void initSetting() {
particleMaxCountTextField.setText(String.valueOf(state.PARTICLE_MAX_COUNT));
particleSizeTextField.setText(String.valueOf(state.PARTICLE_SIZE));
particleMaxCountSlider.setValue(state.PARTICLE_MAX_COUNT);
maxCountValue.setText(String.valueOf(state.PARTICLE_MAX_COUNT));
particleSizeSlider.setValue(state.PARTICLE_SIZE);
sizeValue.setText(String.valueOf(state.PARTICLE_SIZE));

if(state.PARTICLE_COLOR == null) {
colorAutoCheckBox.setSelected(true);
} else {
Expand Down

0 comments on commit 6ce1af7

Please sign in to comment.