Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
247 changes: 121 additions & 126 deletions src/org/aavso/tools/vstar/ui/dialog/TextAreaTabs.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,130 +33,125 @@
*/
public class TextAreaTabs implements ITextComponent<String> {

private boolean canBeEmpty;
private boolean readOnly;

private List<JTextArea> textAreas;

private JTabbedPane tabs;

/**
* Constructor.
*
* @param names
* The list of tab names.
* @param initialValues
* The list of initial text area values.
* @param rows
* The number of rows in these text areas; 0 means don't set;
* applied to all text areas.
* @param cols
* The number of rows in these text areas; 0 means don't set;
* applied to all text areas.
* @param readOnly
* Are all these areas read-only?
* @param canBeEmpty
* Can any of these areas be empty? (all or none)
*/
public TextAreaTabs(List<String> names, List<String> initialValues,
int rows, int cols, boolean readOnly, boolean canBeEmpty) {
assert names.size() == initialValues.size();

this.readOnly = readOnly;
this.canBeEmpty = canBeEmpty;
this.textAreas = new ArrayList<JTextArea>();

List<NamedComponent> namedComponents = new ArrayList<NamedComponent>();

for (int i = 0; i < names.size(); i++) {
JTextArea textArea = new JTextArea(
initialValues.get(i) == null ? "" : initialValues.get(i));

textAreas.add(textArea);

// textArea.setBorder(BorderFactory.createTitledBorder(names.get(i)));
if (!isReadOnly()) {
textArea.setToolTipText("Enter " + names.get(i));
}

namedComponents.add(new NamedComponent(names.get(i),
new JScrollPane(textArea)));
}

for (JTextArea textArea : textAreas) {
if (rows != 0) {
textArea.setRows(rows);
}

if (cols != 0) {
textArea.setColumns(cols);
}
}

tabs = PluginComponentFactory.createTabs(namedComponents);
}

@Override
public String getName() {
return null;
}

@Override
public boolean canBeEmpty() {
return canBeEmpty;
}

@Override
public boolean isReadOnly() {
return readOnly;
}

@Override
public String getValue() {
StringBuffer value = new StringBuffer();

for (JTextArea textArea : textAreas) {
value.append(textArea.getText());
value.append("\n");
}

return value.toString();
}

@Override
public String getStringValue() {
StringBuffer buf = new StringBuffer();

for (JTextArea textArea : textAreas) {
buf.append(textArea.getText());
buf.append("\n");
}

return buf.toString();
}

@Override
public void setEditable(boolean state) {
readOnly = !state;

}

@Override
public void setValue(String value) {
if ("".equals(value)) {
for (JTextArea textArea : textAreas) {
textArea.setText("");
}
} else {
String[] values = value.split("\\<sentinel\\>");
for (int i = 0; i < values.length; i++) {
textAreas.get(i).setText(values[i]);
}
}
}

@Override
public JComponent getUIComponent() {
return tabs;
}
private boolean canBeEmpty;
private boolean readOnly;
private String tabTextseparator;

private List<JTextArea> textAreas;

private JTabbedPane tabs;

/**
* Constructor.
*
* @param names The list of tab names.
* @param initialValues The list of initial text area values.
* @param rows The number of rows in these text areas; 0 means don't
* set; applied to all text areas.
* @param cols The number of rows in these text areas; 0 means don't
* set; applied to all text areas.
* @param readOnly Are all these areas read-only?
* @param canBeEmpty Can any of these areas be empty? (all or none)
* @param tabTextseparator The text value separator for each tabbed text pane.
*/
public TextAreaTabs(List<String> names, List<String> initialValues, int rows, int cols, boolean readOnly,
boolean canBeEmpty, String tabTextseparator) {
assert names.size() == initialValues.size();

this.readOnly = readOnly;
this.canBeEmpty = canBeEmpty;
this.tabTextseparator = tabTextseparator;
this.textAreas = new ArrayList<JTextArea>();

List<NamedComponent> namedComponents = new ArrayList<NamedComponent>();

for (int i = 0; i < names.size(); i++) {
JTextArea textArea = new JTextArea(initialValues.get(i) == null ? "" : initialValues.get(i));

textAreas.add(textArea);

// textArea.setBorder(BorderFactory.createTitledBorder(names.get(i)));
if (!isReadOnly()) {
textArea.setToolTipText("Enter " + names.get(i));
}

namedComponents.add(new NamedComponent(names.get(i), new JScrollPane(textArea)));
}

for (JTextArea textArea : textAreas) {
if (rows != 0) {
textArea.setRows(rows);
}

if (cols != 0) {
textArea.setColumns(cols);
}
}

tabs = PluginComponentFactory.createTabs(namedComponents);
}

@Override
public String getName() {
return null;
}

@Override
public boolean canBeEmpty() {
return canBeEmpty;
}

@Override
public boolean isReadOnly() {
return readOnly;
}

@Override
public String getValue() {
StringBuffer value = new StringBuffer();

for (JTextArea textArea : textAreas) {
value.append(textArea.getText());
value.append("\n");
}

return value.toString();
}

@Override
public String getStringValue() {
StringBuffer buf = new StringBuffer();

for (JTextArea textArea : textAreas) {
buf.append(textArea.getText());
buf.append("\n");
}

return buf.toString();
}

@Override
public void setEditable(boolean state) {
readOnly = !state;

}

@Override
public void setValue(String value) {
if ("".equals(value)) {
for (JTextArea textArea : textAreas) {
textArea.setText("");
}
} else {
String[] values = value.split(tabTextseparator);
for (int i = 0; i < values.length; i++) {
textAreas.get(i).setText(values[i]);
}
}
}

@Override
public JComponent getUIComponent() {
return tabs;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ public class PreferencesDialog extends AbstractOkCancelDialog {
private StarGroupManagementPane starGroupManagementPane;
private PluginSettingsPane pluginSettingsPane;
private LocaleSelectionPane localeSelectionPane;
private VeLaSettingsPane veLaSettingsPane;

/**
* Constructor.
Expand Down Expand Up @@ -86,6 +87,9 @@ private JTabbedPane createTabs() {
localeSelectionPane = new LocaleSelectionPane();
tabs.addTab("Locale", localeSelectionPane);

veLaSettingsPane = new VeLaSettingsPane();
tabs.addTab("VeLa", veLaSettingsPane);

return tabs;
}

Expand All @@ -107,6 +111,7 @@ protected void okAction() {
starGroupManagementPane.update();
pluginSettingsPane.update();
localeSelectionPane.update();
veLaSettingsPane.update();

this.setVisible(false);
}
Expand All @@ -122,6 +127,7 @@ protected void reset() {
starGroupManagementPane.reset();
pluginSettingsPane.reset();
localeSelectionPane.reset();
veLaSettingsPane.reset();
}

/**
Expand Down
Loading