protected static class JTextFieldEx extends JTextField {
private static final long serialVersionUID = -8608404290439184405L;
-
+
private boolean error;
-
+
@Override
public Color getBackground() {
if (error) {
}
return super.getBackground();
}
-
+
public void setError(boolean error) {
if (this.error != error) {
this.error = error;
repaint();
}
}
-
+
public boolean isError() {
return error;
}
}
-
+
/**
* オリジナルのデータ.
*/
private CharacterData original;
-
+
/**
* キャラクターデータID
*/
*/
private JTextField txtCharacterDocBase;
-
+
/**
* キャラクター名
*/
private JTextFieldEx txtCharacterName;
-
+
/**
* イメージ幅
*/
private JSpinner txtImageWidth;
-
+
/**
* イメージ高さ
*/
private JSpinner txtImageHeight;
-
+
/**
* 作者
*/
private JTextField txtAuthor;
-
+
/**
* 説明
*/
private JTextArea txtDescription;
-
+
/**
* ディレクトリの監視
*/
* カテゴリのモデル
*/
private CategoriesTableModel categoriesTableModel;
-
+
/**
* レイヤーのモデル
*/
private LayersTableModel layersTableModel;
-
+
/**
* パーツセットのモデル
*/
private PartssetsTableModel partssetsTableModel;
-
+
/**
* お勧めリンクのモデル
*/
private RecommendationTableModel recommendationsTableModel;
-
-
+
+
/**
* 画面の内容から生成された新しいキャラクターデータ、もしくはnull
*/
private CharacterData result;
-
+
/**
* OKボタン
*/
private JButton btnOK;
-
+
/**
* キャラクターデータの編集画面を構築する.<br>
- *
+ *
* @param parent
* 親、もしくはnull
* @param original
super(parent, true);
initDialog(parent, original);
}
-
+
/**
* キャラクターデータの編集画面を構築する.<br>
- *
+ *
* @param parent
* 親、もしくはnull
* @param original
/**
* 編集ダイアログを初期化する.
- *
+ *
* @param origianl
* 編集もとキャラクター定義
*/
throw new IllegalArgumentException();
}
this.original = original;
-
+
// ウィンドウイベントのハンドル
setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE);
addWindowListener(new WindowAdapter() {
title = strings.getProperty("title.new");
}
setTitle(title);
-
+
// OK/CANCEL PANEL
-
+
JPanel buttonsPanel = new JPanel();
buttonsPanel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 42));
GridBagLayout buttonsPanelLayout = new GridBagLayout();
buttonsPanel.setLayout(buttonsPanelLayout);
GridBagConstraints gbc = new GridBagConstraints();
-
+
String okCaption;
if (original.isValid()) {
okCaption = strings.getProperty("button.ok.edit");
} else {
okCaption = strings.getProperty("button.ok.new");
}
-
+
btnOK = new JButton(new AbstractAction(okCaption) {
private static final long serialVersionUID = 1L;
public void actionPerformed(ActionEvent e) {
}
});
btnOK.setEnabled(false); // 初期状態はディセーブル、updateUIStateで更新する.
-
+
Action actOpenDir = new AbstractAction(strings.getProperty("button.openDir")) {
private static final long serialVersionUID = 1L;
public void actionPerformed(ActionEvent e) {
}
};
JButton btnCancel = new JButton(actCancel);
-
+
gbc.gridx = 0;
gbc.gridy = 0;
gbc.weightx = 0.;
gbc.gridy = 0;
gbc.weightx = 0.;
buttonsPanel.add(btnOK, gbc);
-
+
gbc.gridx = Main.isLinuxOrMacOSX() ? 2 : 3;
gbc.gridy = 0;
buttonsPanel.add(btnCancel, gbc);
-
+
Container contentPane = getContentPane();
contentPane.setLayout(new BorderLayout());
contentPane.add(buttonsPanel, BorderLayout.SOUTH);
// InputMap/ActionMap
-
+
Toolkit tk = Toolkit.getDefaultToolkit();
JRootPane rootPane = getRootPane();
rootPane.setDefaultButton(btnOK);
im.put(KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), "closeWindow");
im.put(KeyStroke.getKeyStroke(KeyEvent.VK_W, tk.getMenuShortcutKeyMask()), "closeWindow");
rootPane.getActionMap().put("closeWindow", actCancel);
-
+
// Main
JPanel mainPanel = new JPanel();
GridBagLayout mainPanelLayout = new GridBagLayout();
mainPanel.setLayout(mainPanelLayout);
-
+
this.txtCharacterID = new JTextFieldEx();
this.txtCharacterRev = new JTextFieldEx();
this.txtCharacterDocBase = new JTextField();
Integer.MAX_VALUE, 1)); // 現実に可能であるかを問わず制限を設けない
this.txtAuthor = new JTextField();
this.txtDescription = new JTextArea();
-
+
gbc.gridx = 0;
gbc.gridy = 0;
gbc.gridwidth = 1;
gbc.anchor = GridBagConstraints.EAST;
gbc.fill = GridBagConstraints.BOTH;
mainPanel.add(new JLabel(strings.getProperty("id.caption"), SwingConstants.RIGHT), gbc);
-
+
txtCharacterID.setToolTipText(strings.getProperty("id.caption.help"));
txtCharacterRev.setToolTipText(strings.getProperty("rev.caption.help"));
gbc.anchor = GridBagConstraints.EAST;
gbc.fill = GridBagConstraints.BOTH;
mainPanel.add(txtCharacterID, gbc);
-
+
gbc.gridx = 0;
gbc.gridy = 2;
gbc.gridwidth = 1;
gbc.anchor = GridBagConstraints.EAST;
gbc.fill = GridBagConstraints.BOTH;
mainPanel.add(txtCharacterRev, gbc);
-
-
+
+
gbc.gridx = 0;
gbc.gridy = 3;
gbc.gridwidth = 1;
mainPanel.add(new JScrollPane(txtDescription), gbc);
// model
-
+
this.colorGroupsTableModel = new ColorGroupsTableModel();
this.categoriesTableModel = new CategoriesTableModel();
this.layersTableModel = new LayersTableModel();
this.partssetsTableModel = new PartssetsTableModel();
this.recommendationsTableModel = new RecommendationTableModel();
-
+
this.colorGroupsTableModel.setEditable(true);
this.categoriesTableModel.setEditable(true);
this.layersTableModel.setEditable(true);
this.partssetsTableModel.setEditable(true);
this.recommendationsTableModel.setEditable(true);
-
+
// colorGroup
JPanel colorGroupPanel = new JPanel(new BorderLayout());
final JTable colorGroupTable = new JTable(colorGroupsTableModel);
colorGroupTable.setRowHeight(colorGroupTable.getRowHeight() + 4);
colorGroupTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
colorGroupPanel.add(new JScrollPane(colorGroupTable), BorderLayout.CENTER);
-
+
JPanel colorGroupBtnPanel = new JPanel();
GridBagLayout colorGroupBtnPanelLayout = new GridBagLayout();
colorGroupBtnPanel.setLayout(colorGroupBtnPanelLayout);
}
}
};
-
-
+
+
gbc.gridx = 0;
gbc.gridy = 0;
gbc.gridwidth = 1;
gbc.anchor = GridBagConstraints.EAST;
gbc.fill = GridBagConstraints.BOTH;
colorGroupBtnPanel.add(new JButton(actColorGroupAdd), gbc);
-
+
gbc.gridx = 0;
gbc.gridy = 1;
colorGroupBtnPanel.add(new JButton(actColorGroupDel), gbc);
colorGroupBtnPanel.add(Box.createGlue(), gbc);
colorGroupPanel.add(colorGroupBtnPanel, BorderLayout.EAST);
-
+
final Color disabledForeground = appConfig.getDisabledCellForgroundColor();
// categories
categoriesTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
categoriesTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
categoriesPanel.add(new JScrollPane(categoriesTable), BorderLayout.CENTER);
-
+
categoriesTableModel.adjustColumnModel(categoriesTable.getColumnModel());
-
+
JPanel categoriesBtnPanel = new JPanel();
GridBagLayout categoryBtnPanelLayout = new GridBagLayout();
categoriesBtnPanel.setLayout(categoryBtnPanelLayout);
-
+
AbstractAction actCategoryAdd = new AbstractAction(strings.getProperty("categories.add.caption")) {
private static final long serialVersionUID = 1L;
public void actionPerformed(ActionEvent e) {
gbc.anchor = GridBagConstraints.EAST;
gbc.fill = GridBagConstraints.BOTH;
categoriesBtnPanel.add(new JButton(actCategoryAdd), gbc);
-
+
gbc.gridx = 0;
gbc.gridy = 1;
categoriesBtnPanel.add(new JButton(actCategoryDel), gbc);
categoriesPanel.add(categoriesBtnPanel, BorderLayout.EAST);
-
+
// layers
JPanel layersPanel = new JPanel(new BorderLayout());
final Color invalidBgColor = appConfig.getInvalidBgColor();
public Component prepareRenderer(TableCellRenderer renderer,
int row, int column) {
Component comp = super.prepareRenderer(renderer, row, column);
-
+
if (comp instanceof JCheckBox) {
// BooleanのデフォルトのレンダラーはJCheckBoxを継承したJTable$BooleanRenderer
comp.setEnabled(isCellEditable(row, column) && isEnabled());
}
-
+
LayersTableModel model = (LayersTableModel) getModel();
LayersTableRow layer = model.getRow(row);
comp.setForeground(getForeground());
// 前景色、ディセーブル時は灰色
Color foregroundColor = getForeground();
comp.setForeground(isEnabled() ? foregroundColor : disabledForeground);
-
+
return comp;
}
};
new FirstItemInjectionComboBoxModelWrapper<ColorGroupsTableRow>(colorGroupsTableModel, ColorGroupsTableRow.NA));
JComboBox categoriesCombo = new JComboBox(categoriesTableModel);
JComboBox colorModelsCombo = new JComboBox(ColorModels.values());
-
+
layersTable.setShowGrid(true);
layersTable.setGridColor(appConfig.getGridColor());
layersTable.putClientProperty("terminateEditOnFocusLost", Boolean.TRUE);
layersTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
layersTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
layersPanel.add(new JScrollPane(layersTable), BorderLayout.CENTER);
-
+
JPanel layersBtnPanel = new JPanel();
GridBagLayout layersBtnPanelLayout = new GridBagLayout();
layersBtnPanel.setLayout(layersBtnPanelLayout);
-
+
AbstractAction actLayerAdd = new AbstractAction(strings.getProperty("layers.add.caption")) {
private static final long serialVersionUID = 1L;
public void actionPerformed(ActionEvent e) {
}
}
};
-
+
gbc.gridx = 0;
gbc.gridy = 0;
gbc.gridwidth = 1;
gbc.anchor = GridBagConstraints.EAST;
gbc.fill = GridBagConstraints.BOTH;
layersBtnPanel.add(new JButton(actLayerAdd), gbc);
-
+
gbc.gridx = 0;
gbc.gridy = 1;
layersBtnPanel.add(new JButton(actLayerDel), gbc);
layersBtnPanel.add(Box.createGlue(), gbc);
layersPanel.add(layersBtnPanel, BorderLayout.EAST);
-
+
chkWatchDir = new JCheckBox(strings.getProperty("layers.watchdir"));
layersPanel.add(chkWatchDir, BorderLayout.SOUTH);
-
+
// Presets
JPanel partssetsPanel = new JPanel(new BorderLayout());
JTable partssetsTable = new JTable(partssetsTableModel) {
JPanel recommendationsBtnPanel = new JPanel();
GridBagLayout recommendationsBtnPanelLayout = new GridBagLayout();
recommendationsBtnPanel.setLayout(recommendationsBtnPanelLayout);
-
+
AbstractAction actRecommendationAdd = new AbstractAction(strings.getProperty("recommendations.add.caption")) {
private static final long serialVersionUID = 1L;
public void actionPerformed(ActionEvent e) {
}
}
};
-
+
gbc.gridx = 0;
gbc.gridy = 0;
gbc.gridwidth = 1;
gbc.anchor = GridBagConstraints.EAST;
gbc.fill = GridBagConstraints.BOTH;
recommendationsBtnPanel.add(new JButton(actRecommendationAdd), gbc);
-
+
gbc.gridx = 0;
gbc.gridy = 1;
recommendationsBtnPanel.add(new JButton(actRecommendationDel), gbc);
recommendationsBtnPanel.add(Box.createGlue(), gbc);
recommendationsPanel.add(recommendationsBtnPanel, BorderLayout.EAST);
-
-
+
+
// データのロード
loadCharacterData(original);
-
+
// レイヤーのカテゴリ使用状態を監視するリスナ関連
final HashMap<CategoriesTableRow, List<LayersTableRow>> usedLayerMap = new HashMap<CategoriesTableRow, List<LayersTableRow>>();
final Runnable resetUsedLayers = new Runnable() {
return usedLayerMap.get(partsCategory);
}
});
-
+
// 生成可能であるかチェックするためのリスナ
layersTableModel.addListDataListener(new ListDataListener() {
public void contentsChanged(ListDataEvent e) {
updateUIState();
}
});
-
+
// キャラクターID/REV/NAMEが変更されたことを通知され、OKボタンを判定するためのリスナ
DocumentListener textChangeListener = new DocumentListener() {
public void removeUpdate(DocumentEvent e) {
txtCharacterID.getDocument().addDocumentListener(textChangeListener);
txtCharacterRev.getDocument().addDocumentListener(textChangeListener);
txtCharacterName.getDocument().addDocumentListener(textChangeListener);
-
+
// TABS
-
+
JTabbedPane tabbedPane = new JTabbedPane();
tabbedPane.add(strings.getProperty("panel.basicinfomation"), mainPanel);
tabbedPane.add(strings.getProperty("panel.colorgroup"), colorGroupPanel);
tabbedPane.add(strings.getProperty("panel.layers"), layersPanel);
tabbedPane.add(strings.getProperty("panel.partssets"), partssetsPanel);
tabbedPane.add(strings.getProperty("panel.recommendations"), recommendationsPanel);
-
+
contentPane.add(tabbedPane, BorderLayout.CENTER);
-
+
setSize(500, 500);
setLocationRelativeTo(parent);
updateUIState();
}
-
+
/**
* CharacterDataから画面へ転記する.
- *
+ *
* @param original
* オリジナル情報
*/
// 基本情報
txtCharacterID.setText(original.getId());
txtCharacterRev.setText(original.getRev());
-
+
txtCharacterDocBase.setText(original.getDocBase() == null ? "" : original.getDocBase().toString());
txtCharacterName.setText(original.getName());
colorGroupMap.put(colorGroup, mutableColorGroup);
}
}
-
+
// カテゴリとレイヤー
for (PartsCategory partsCategory : original.getPartsCategories()) {
categoriesTableModel.addRow(new CategoriesTableRow(partsCategory));
layersTableModel.addRow(editableLayer);
}
}
-
+
// ディレクトリ監視有無
chkWatchDir.setSelected(original.isWatchDirectory());
-
+
// パーツセット
ArrayList<PartsSet> partsSets = new ArrayList<PartsSet>();
partsSets.addAll(original.getPartsSets().values());
}
}
}
-
+
protected void onOpenDir() {
try {
ErrorMessageHelper.showErrorDialog(this, ex);
}
}
-
+
/**
* 画面を閉じる場合
*/
protected void onClose() {
result = null;
-
+
boolean writable = !original.isValid() || original.canWrite(); // 新規または更新可能
if (writable) {
final Properties strings = LocalizedResourcePropertyLoader
}
dispose();
}
-
+
/**
* 画面の状態を更新する
*/
}
private interface ValidationReport {
-
+
void validateReport(JComponent comp, boolean valid);
-
+
}
/**
* 入力データが有効であるか判定する.
- *
+ *
* @return 有効であればtrue
*/
protected boolean isValidData(ValidationReport report) {
-
+
// ID, REVが英数字であるか判定
Pattern pat = Pattern.compile("\\p{Graph}+");
String id = txtCharacterID.getText().trim();
report.validateReport(txtCharacterRev, validRev);
report.validateReport(txtCharacterName, validName);
}
-
+
return validLayers && validId && validRev && validName;
}
-
+
/**
* OKボタン押下
*/
}
// 編集可能であり、且つ、保存可能な状態であれば
- CharacterData newCd = createCharacterData();
+ CharacterData newCd = createCharacterData();
final Properties strings = LocalizedResourcePropertyLoader
.getCachedInstance().getLocalizedProperties(STRINGS_RESOURCE);
if (original.isValid() && !original.isSameStructure(newCd)) {
int ret = JOptionPane.showConfirmDialog(this,
strings.get("confirm.needchangerevision"),
strings.getProperty("confirm"),
- JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.WARNING_MESSAGE);
+ JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.WARNING_MESSAGE);
if (ret == JOptionPane.CANCEL_OPTION) {
return;
}
CharacterDataPersistent persist = CharacterDataPersistent.getInstance();
newCd.setRev(persist.generateRev());
}
-
+
} else if ( !newCd.isUpperCompatibleStructure(original)){
// 上位互換のない構造が変更されていることを通知する.
if (JOptionPane.showConfirmDialog(this,
dispose();
return;
}
-
+
/**
* 画面の情報からキャラクターデータを構築して返します.<br>
- *
+ *
* @return キャラクターデータ
*/
protected CharacterData createCharacterData() {
// オリジナルのDocBaseVを転記する.
cd.setDocBase(original.getDocBase());
-
+
// ID, REV
cd.setId(txtCharacterID.getText().trim());
cd.setRev(txtCharacterRev.getText().trim());
// キャラクターセット名
cd.setName(txtCharacterName.getText().trim());
-
+
// 情報
cd.setAuthor(txtAuthor.getText().trim());
cd.setDescription(txtDescription.getText());
-
+
// サイズ
Dimension imageSize = new Dimension();
imageSize.width = ((Number)(txtImageWidth.getValue())).intValue();
imageSize.height = ((Number)(txtImageHeight.getValue())).intValue();
cd.setImageSize(imageSize);
-
+
// カラーグループ
int mxColorGroup = colorGroupsTableModel.getRowCount();
ArrayList<ColorGroup> colorGroups = new ArrayList<ColorGroup>();
colorGroups.add(colorGroupsTableModel.getRow(idx).convert());
}
cd.setColorGroups(colorGroups);
-
+
// レイヤーの構築
HashMap<CategoriesTableRow, List<Layer>> layerMap = new HashMap<CategoriesTableRow, List<Layer>>();
int mxLayer = layersTableModel.getRowCount();
layers.add(layer);
}
}
-
+
// カテゴリおよびレイヤー
ArrayList<PartsCategory> categories = new ArrayList<PartsCategory>();
int mxCategory = categoriesTableModel.getRowCount();
// ディレクトリの監視
cd.setWatchDirectory(chkWatchDir.isSelected());
-
+
// パーツセット情報
int mxPartssets = partssetsTableModel.getRowCount();
for (int idx = 0; idx < mxPartssets; idx++) {
cd.addPartsSet(partsSet);
}
cd.setDefaultPartsSetId(partssetsTableModel.getDefaultPartsSetId());
-
+
// お気に入りリンク情報
int mxRecommendations = recommendationsTableModel.getRowCount();
ArrayList<RecommendationURL> recommendationURLList = new ArrayList<RecommendationURL>();
recommendationURLList = null;
}
cd.setRecommendationURLList(recommendationURLList);
-
+
return cd;
}
-
+
/**
* 結果を取得する. キャンセルされた場合はnullが返される.<br>
- *
+ *
* @return キャラクターデータ、またはnull
*/
public CharacterData getResult() {
return result;
}
-
+
}
/**
* 編集用カラーグループ
- *
+ *
* @author seraphy
*/
class ColorGroupsTableRow {
private final String id;
-
+
private final boolean enabled;
-
+
private String localizedName;
public static final ColorGroupsTableRow NA = new ColorGroupsTableRow("n/a", "", false);
-
-
+
+
public ColorGroupsTableRow(final String id, final String localizedName) {
this(id, localizedName, true);
}
-
+
public static ColorGroupsTableRow valueOf(ColorGroup colorGroup) {
if (colorGroup == null || !colorGroup.isEnabled()) {
return NA;
}
return new ColorGroupsTableRow(colorGroup.getId(), colorGroup.getLocalizedName(), true);
}
-
+
public ColorGroup convert() {
if (!isEnabled()) {
return ColorGroup.NA;
}
return new ColorGroup(getId(), getLocalizedName());
}
-
+
private ColorGroupsTableRow(final String id, final String localizedName, final boolean enabled) {
if (id == null || id.trim().length() == 0) {
throw new IllegalArgumentException();
this.localizedName = (localizedName == null || localizedName.trim().length() == 0) ? id : localizedName;
this.enabled = enabled;
}
-
+
public void setLocalizedName(String localizedName) {
if (localizedName == null || localizedName.trim().length() == 0) {
throw new IllegalArgumentException();
}
this.localizedName = localizedName;
}
-
+
public boolean isEnabled() {
return enabled;
}
-
+
public String getId() {
return id;
}
-
+
public String getLocalizedName() {
return localizedName;
}
-
+
@Override
public int hashCode() {
return id.hashCode();
}
-
+
@Override
public boolean equals(Object obj) {
if (obj == this) {
}
return false;
}
-
+
public static boolean equals(ColorGroupsTableRow v1, ColorGroupsTableRow v2) {
if (v1 == v2) {
return true;
}
return v1.equals(v2);
}
-
+
@Override
public String toString() {
return getLocalizedName();
/**
* カラーグループのテーブル編集モデル
- *
+ *
* @author seraphy
*/
class ColorGroupsTableModel extends AbstractTableModelWithComboBoxModel<ColorGroupsTableRow> {
private static final long serialVersionUID = 2952439955567262351L;
private static final String[] colorGroupColumnNames;
-
+
private static final Logger logger = Logger.getLogger(ColorGroupsTableModel.class.getName());
static {
strings.getProperty("colorgroup.column.colorgroupname"),
};
}
-
+
private int serialCounter = 1;
-
+
public int getColumnCount() {
return colorGroupColumnNames.length;
}
-
+
@Override
public String getColumnName(int column) {
return colorGroupColumnNames[column];
}
return "****";
}
-
+
@Override
public void setValueAt(Object aValue, int rowIndex, int columnIndex) {
ColorGroupsTableRow colorGroup = elements.get(rowIndex);
return;
}
fireTableCellUpdated(rowIndex, columnIndex);
-
+
} catch (Exception ex) {
logger.log(Level.FINE, "value set failed. (" + rowIndex + ", " + columnIndex + "): " + aValue, ex);
// 無視する
}
}
-
+
@Override
public Class<?> getColumnClass(int columnIndex) {
return String.class;
}
-
+
@Override
public boolean isCellEditable(int rowIndex, int columnIndex) {
return isEditable();
/**
* カラーグループ用のコンボボックスモデルに対して最初のアイテムとしてN/Aを常に追加するモデルに変換するラップクラス.<br>
- *
+ *
* @author seraphy
*/
class FirstItemInjectionComboBoxModelWrapper<T> implements ComboBoxModel {
-
+
private ComboBoxModel parent;
-
+
private T selectedItem;
-
+
private T firstItem;
-
+
private LinkedList<ListDataListener> listDataListeners = new LinkedList<ListDataListener>();
public FirstItemInjectionComboBoxModelWrapper(ComboBoxModel parent, T firstItem) {
if (parent == null || firstItem == null) {
throw new IllegalArgumentException();
}
-
+
this.parent = parent;
this.firstItem = firstItem;
}
/**
* 親コンボボックスモデルのインデックスを+1したイベントに変換する.
- *
+ *
* @param e
* 元イベント
* @return インデックス変換後のイベント
listener.intervalRemoved(e);
}
}
-
+
public Object getSelectedItem() {
return selectedItem;
}
* 順序
*/
private int order;
-
+
/**
* カテゴリ識別名
*/
private String categoryId;
-
+
/**
* カテゴリ表示名
*/
* 複数選択可能?
*/
private boolean multipleSelectable;
-
+
+ /**
+ * 省略可能?
+ */
+ private boolean optional;
+
/**
* 表示行数
*/
private int visibleRows;
-
+
/**
* レイヤー情報
*/
private ArrayList<Layer> layers = new ArrayList<Layer>();
-
+
/**
* カテゴリを構築する.<br>
- *
+ *
* @param categoryId
* カテゴリ識別名
* @param localizedCategoryName
* レイヤー情報の配列
*/
public CategoriesTableRow(final int order, final String categoryId, String localizedCategoryName,
- boolean multipleSelectable, int visibleRows, Layer[] layers) {
+ boolean multipleSelectable, boolean optional, int visibleRows, Layer[] layers) {
if (categoryId == null || categoryId.trim().length() == 0) {
throw new IllegalArgumentException();
}
this.categoryId = categoryId.trim();
this.localizedCategoryName = localizedCategoryName.trim();
this.multipleSelectable = multipleSelectable;
+ this.optional = optional;
this.layers.addAll(Arrays.asList(layers));
this.visibleRows = visibleRows;
}
-
+
public CategoriesTableRow(PartsCategory partsCategory) {
if (partsCategory == null) {
throw new IllegalArgumentException();
this.categoryId = partsCategory.getCategoryId();
this.localizedCategoryName = partsCategory.getLocalizedCategoryName();
this.multipleSelectable = partsCategory.isMultipleSelectable();
+ this.optional = partsCategory.isOptional();
this.layers.addAll(partsCategory.getLayers());
this.visibleRows = partsCategory.getVisibleRows();
}
-
+
public PartsCategory convert() {
return new PartsCategory(order, categoryId, localizedCategoryName,
- multipleSelectable, visibleRows, layers
+ multipleSelectable, optional, visibleRows, layers
.toArray(new Layer[layers.size()]));
}
-
+
public int compareTo(CategoriesTableRow o) {
if (o == this) {
return 0;
}
return ret;
}
-
+
@Override
public boolean equals(Object obj) {
if (obj == this) {
}
return false;
}
-
+
public static boolean equals(CategoriesTableRow o1, CategoriesTableRow o2) {
if (o1 == o2) {
return true;
}
return o1.equals(o2);
}
-
+
/**
* 定義順を取得する
- *
+ *
* @return 定義順
*/
public int getOrder() {
/**
* 定義順を設定する
- *
+ *
* @param order
* 定義順
*/
public void setOrder(int order) {
this.order = order;
}
-
+
/**
* 複数選択可能であるか?
- *
+ *
* @return 複数選択可能であるか?
*/
public boolean isMultipleSelectable() {
/**
* 複数選択可能であるか設定する
- *
+ *
* @param multipleSelectable
* 複数選択可能であればtrue
*/
}
/**
+ * 省略可能か?
+ * @return
+ */
+ public boolean isOptional() {
+ return optional;
+ }
+
+ /**
+ * 省略可能か設定する。
+ * @param optional
+ */
+ public void setOptional(boolean optional) {
+ this.optional = optional;
+ }
+
+ /**
* 表示行数を取得する.
- *
+ *
* @return 表示行数
*/
public int getVisibleRows() {
/**
* 表示行数を設定する
- *
+ *
* @param visibleRows
* 表示行数
*/
public void setVisibleRows(int visibleRows) {
this.visibleRows = visibleRows;
}
-
+
/**
* このカテゴリに指定したレイヤーが含まれるか検証する.
- *
+ *
* @param layer
* レイヤー
* @return 含まれる場合はtrue、含まれない場合はfalse
}
return false;
}
-
+
/**
* レイヤー情報
- *
+ *
* @return レイヤー情報
*/
public Collection<Layer> getLayers() {
return Collections.unmodifiableCollection(layers);
}
-
+
/**
* レイヤー情報
- *
+ *
* @param layers
*/
public void setLayers(Collection<Layer> layers) {
this.layers.addAll(layers);
}
}
-
+
/**
* レイヤーを取得する.<br>
* 該当するレイヤーがなければnull
- *
+ *
* @param layerId
* レイヤー名
* @return レイヤーもしくはnull
}
return null;
}
-
+
/**
* カテゴリ識別名を取得する.
- *
+ *
* @return カテゴリ識別名
*/
public String getCategoryId() {
return categoryId;
}
-
+
/**
* カテゴリ表示名を取得する.
- *
+ *
* @return カテゴリ表示名
*/
public String getLocalizedCategoryName() {
return this.localizedCategoryName;
}
-
+
/**
* カテゴリ表示名を設定する.
- *
+ *
* @param localizedCategoryName
* カテゴリ表示名
*/
}
this.localizedCategoryName = localizedCategoryName.trim();
}
-
+
@Override
public int hashCode() {
return this.categoryId.hashCode();
}
-
+
@Override
public String toString() {
return getLocalizedCategoryName();
}
-
}
/**
* カテゴリのテーブル編集モデル.
- *
+ *
* @author seraphy
- *
+ *
*/
class CategoriesTableModel extends AbstractTableModelWithComboBoxModel<CategoriesTableRow> {
-
+
private static final long serialVersionUID = 1L;
-
+
private static final Logger logger = Logger.getLogger(CategoriesTableModel.class.getName());
public interface UsedCategoryDetector {
-
+
List<LayersTableRow> getLayers(CategoriesTableRow partsCategory);
-
}
-
- private static final String[] categoriesColumnName;
-
- private static final int[] categoriesColumnWidths;
-
- static {
- final Properties strings = LocalizedResourcePropertyLoader
- .getCachedInstance().getLocalizedProperties(ProfileEditDialog.STRINGS_RESOURCE);
- categoriesColumnName = new String[] {
- strings.getProperty("categories.column.categoryname"),
- strings.getProperty("categories.column.multipleselectable"),
- strings.getProperty("categories.column.displayrowcount"),
- strings.getProperty("categories.column.usedlayers"),
- };
- categoriesColumnWidths = new int[] {
- Integer.parseInt(strings.getProperty("categories.column.categoryname.width")),
- Integer.parseInt(strings.getProperty("categories.column.multipleselectable.width")),
- Integer.parseInt(strings.getProperty("categories.column.displayrowcount.width")),
- Integer.parseInt(strings.getProperty("categories.column.usedlayers.width")),
+
+ enum ColumnDef {
+ CATEGORY_NAME("categories.column.categoryname", true, String.class) {
+ @Override
+ public Object getValue(CategoriesTableRow row) {
+ return row.getLocalizedCategoryName();
+ }
+ @Override
+ public void setValue(CategoriesTableRow row, Object aValue) {
+ row.setLocalizedCategoryName((String) aValue);
+ }
+ },
+ MULTIPLE_SELECTABLE("categories.column.multipleselectable", true, Boolean.class) {
+ @Override
+ public Object getValue(CategoriesTableRow row) {
+ return Boolean.valueOf(row.isMultipleSelectable());
+ }
+ @Override
+ public void setValue(CategoriesTableRow row, Object aValue) {
+ row.setMultipleSelectable(((Boolean) aValue).booleanValue());
+ }
+ },
+ OPTIONAL("categories.column.optional", true, Boolean.class) {
+ @Override
+ public Object getValue(CategoriesTableRow row) {
+ return Boolean.valueOf(row.isOptional());
+ }
+ @Override
+ public void setValue(CategoriesTableRow row, Object aValue) {
+ row.setOptional(((Boolean) aValue).booleanValue());
+ }
+ },
+ DISPLAY_ROW_COUNT("categories.column.displayrowcount", true, Integer.class) {
+ @Override
+ public Object getValue(CategoriesTableRow row) {
+ return row.getVisibleRows();
+ }
+ @Override
+ public void setValue(CategoriesTableRow row, Object aValue) {
+ row.setVisibleRows(((Number) aValue).intValue());
+ }
+ },
+ USED_LAYERS("categories.column.usedlayers", false, String.class) {
+ @Override
+ public Object getValue(CategoriesTableRow row) {
+ return null;
+ }
};
+
+ private final String reskey;
+
+ private final boolean editable;
+
+ private final Class<?> dataType;
+
+ ColumnDef(String reskey, boolean editable, Class<?> dataType) {
+ this.reskey = reskey;
+ this.editable = editable;
+ this.dataType = dataType;
+ }
+
+ public Class<?> getDataType() {
+ return dataType;
+ }
+
+ public boolean isEditable() {
+ return editable;
+ }
+
+ public String getResourceKey() {
+ return reskey;
+ }
+
+ public abstract Object getValue(CategoriesTableRow row);
+
+ public void setValue(CategoriesTableRow row, Object value) {
+ throw new UnsupportedOperationException(name());
+ }
}
-
+
+ private static final Properties strings = LocalizedResourcePropertyLoader
+ .getCachedInstance().getLocalizedProperties(ProfileEditDialog.STRINGS_RESOURCE);
+
+ private static final ColumnDef[] COLUMNS = ColumnDef.values();
+
private int serialCounter = 1;
private UsedCategoryDetector usedCategoryDetector;
-
+
public CategoriesTableModel() {
}
-
+
public void adjustColumnModel(TableColumnModel columnModel) {
- for (int idx = 0; idx < categoriesColumnWidths.length; idx++) {
- columnModel.getColumn(idx).setPreferredWidth(categoriesColumnWidths[idx]);
+ for (int idx = 0; idx < COLUMNS.length; idx++) {
+ ColumnDef columnDef = COLUMNS[idx];
+ String reskey = columnDef.getResourceKey();
+ int width = Integer.parseInt(strings.getProperty(reskey + ".width"));
+ columnModel.getColumn(idx).setPreferredWidth(width);
}
}
UsedCategoryDetector usedCategoryDetector) {
this.usedCategoryDetector = usedCategoryDetector;
}
-
+
public UsedCategoryDetector getUsedCategoryDetector() {
return usedCategoryDetector;
}
-
+
public void addCategory() {
String id = "cat" + UUID.randomUUID().toString();
String name = "Category" + (serialCounter++);
CategoriesTableRow partsCategory = new CategoriesTableRow(
- serialCounter, id, name, false, 10, null);
+ serialCounter, id, name, false, true, 10, null);
addRow(partsCategory);
}
-
+
/**
* 定義順を振り直す.
*/
}
fireTableDataChanged();
}
-
+
@Override
public int moveDown(int rowIndex) {
int ret = super.moveDown(rowIndex);
reorder();
return ret;
}
-
+
@Override
public int moveUp(int rowIndex) {
int ret = super.moveUp(rowIndex);
reorder();
return ret;
}
-
+
@Override
public String getColumnName(int column) {
- return categoriesColumnName[column];
+ String reskey = COLUMNS[column].getResourceKey();
+ return strings.getProperty(reskey, reskey);
}
-
+
public int getColumnCount() {
- return categoriesColumnName.length;
+ return COLUMNS.length;
}
-
+
public Object getValueAt(int rowIndex, int columnIndex) {
CategoriesTableRow partsCategory = elements.get(rowIndex);
- switch (columnIndex) {
- case 0:
- return partsCategory.getLocalizedCategoryName();
- case 1:
- return Boolean.valueOf(partsCategory.isMultipleSelectable());
- case 2:
- return partsCategory.getVisibleRows();
- case 3:
+ ColumnDef columnDef = COLUMNS[columnIndex];
+ if (columnDef == ColumnDef.USED_LAYERS) {
+ // USED_LAYERSカラムは行データの外部からデータを収集して表示する
StringBuilder layerNames = new StringBuilder();
List<LayersTableRow> layers = null;
if (usedCategoryDetector != null) {
}
}
return layerNames.toString();
- default:
- return "***";
}
+
+ // USED_LAYERSカラム以外
+ return columnDef.getValue(partsCategory);
}
-
+
@Override
public void setValueAt(Object aValue, int rowIndex, int columnIndex) {
CategoriesTableRow partsCategory = elements.get(rowIndex);
try {
- switch (columnIndex) {
- case 0:
- partsCategory.setLocalizedCategoryName((String) aValue);
- break;
- case 1:
- partsCategory.setMultipleSelectable(((Boolean) aValue).booleanValue());
- break;
- case 2:
- partsCategory.setVisibleRows(((Number) aValue).intValue());
- break;
- default:
- return;
+ ColumnDef columnDef = COLUMNS[columnIndex];
+ if (columnDef.isEditable()) {
+ columnDef.setValue(partsCategory, aValue);
+ fireTableCellUpdated(rowIndex, columnIndex);
}
- fireTableCellUpdated(rowIndex, columnIndex);
} catch (RuntimeException ex) {
logger.log(Level.FINE, "value set failed. (" + rowIndex + ", " + columnIndex + "): " + aValue, ex);
// 無視する.
}
}
-
+
@Override
public Class<?> getColumnClass(int columnIndex) {
- if (columnIndex == 1) {
- return Boolean.class;
- }
- if (columnIndex == 2) {
- return Integer.class;
- }
- return String.class;
+ return COLUMNS[columnIndex].getDataType();
}
@Override
public boolean isCellEditable(int rowIndex, int columnIndex) {
- if (columnIndex >= categoriesColumnName.length - 1) {
- return false;
- }
- return isEditable();
+ return isEditable() && COLUMNS[columnIndex].isEditable();
}
}
/**
* レイヤーのテーブル編集モデル
- *
+ *
* @author seraphy
*/
class LayersTableModel extends AbstractTableModelWithComboBoxModel<LayersTableRow> {
-
+
private static final long serialVersionUID = 1L;
-
+
private static final Logger logger = Logger.getLogger(LayersTableModel.class.getName());
private static final String[] layerColumnNames;
-
+
private static final int[] layersColumnWidths;
-
+
private enum Columns {
/**
* レイヤー名
public abstract boolean setValue(LayersTableRow layer, Object aValue);
}
-
+
static {
final Properties strings = LocalizedResourcePropertyLoader
.getCachedInstance().getLocalizedProperties(ProfileEditDialog.STRINGS_RESOURCE);
CategoriesTableRow p1 = o1.getPartsCategory();
CategoriesTableRow p2 = o2.getPartsCategory();
-
+
if (p1 == p2) {
ret = 0;
} else if (p1 != null && p2 != null) {
/**
* レイヤーのテーブル編集モデルで使うレイヤー編集クラス
- *
+ *
* @author seraphy
*/
class LayersTableRow {
private String layerId;
-
+
private String layerName;
-
+
private CategoriesTableRow partsCategory;
-
+
private ColorGroupsTableRow colorGroup = ColorGroupsTableRow.NA;
-
+
private int order;
-
+
private String dir;
-
+
private ColorModels colorModel = ColorModels.DEFAULT;
public LayersTableRow() {
super();
}
-
+
public String getLayerId() {
return layerId;
}
throw new IllegalArgumentException();
}
dir = dir.trim();
-
+
if (dir.indexOf("/") >= 0 || dir.indexOf("\\") >= 0 || dir.indexOf("..") >= 0 || dir.endsWith(".")) {
throw new IllegalArgumentException("not simple name: " + dir);
}
-
+
this.dir = dir;
}
-
+
public ColorModels getColorModel() {
return colorModel;
}
return layerName != null && layerName.trim().length() > 0
&& dir != null && dir.trim().length() > 0 && partsCategory != null && colorGroup != null;
}
-
+
public Layer toLayer() {
if (!isValid()) {
return null;
/**
* パーツセットのテーブルの行編集モデル
- *
+ *
* @author seraphy
*/
class PresetsTableRow {
-
+
private PartsSet partsSet;
-
+
public PresetsTableRow(PartsSet partsSet) {
if (partsSet == null) {
throw new IllegalArgumentException();
}
this.partsSet = partsSet.clone();
}
-
+
public String getPartsSetId() {
return partsSet.getPartsSetId();
}
-
+
public String getLocalizedName() {
return partsSet.getLocalizedName();
}
-
+
public void setLocalizedName(String localizedName) {
partsSet.setLocalizedName(localizedName);
}
-
+
public boolean isPresetParts() {
return partsSet.isPresetParts();
}
-
+
public void setPresetParts(boolean checked) {
partsSet.setPresetParts(checked);
}
-
+
public PartsSet convert() {
return partsSet.clone();
}
-
+
}
/**
* パーツセットのテーブル編集モデル
- *
+ *
* @author seraphy
*/
class PartssetsTableModel extends AbstractTableModelWithComboBoxModel<PresetsTableRow> {
-
+
private static final long serialVersionUID = 1L;
-
+
private static final Logger logger = Logger.getLogger(PartssetsTableModel.class.getName());
private static final String[] partssetsColumnNames;
-
+
private static final int[] partssetsColumnWidths;
-
+
private String defaultPartsSetId;
-
+
static {
final Properties strings = LocalizedResourcePropertyLoader
.getCachedInstance().getLocalizedProperties(ProfileEditDialog.STRINGS_RESOURCE);
public PartssetsTableModel() {
}
-
+
public void setDefaultPartsSetId(String defaultPartsSetId) {
this.defaultPartsSetId = defaultPartsSetId;
}
-
+
public String getDefaultPartsSetId() {
return defaultPartsSetId;
}
-
+
public void adjustColumnModel(TableColumnModel columnModel) {
for (int idx = 0; idx < partssetsColumnWidths.length; idx++) {
columnModel.getColumn(idx).setPreferredWidth(partssetsColumnWidths[idx]);
}
}
-
+
public int getColumnCount() {
return partssetsColumnNames.length;
}
-
+
@Override
public String getColumnName(int column) {
return partssetsColumnNames[column];
}
-
-
+
+
public Object getValueAt(int rowIndex, int columnIndex) {
PresetsTableRow rowModel = elements.get(rowIndex);
switch (columnIndex) {
return null;
}
}
-
+
private String getUsedParts(PresetsTableRow rowModel) {
StringBuilder buf = new StringBuilder();
PartsSet partsSet = rowModel.convert();
}
return buf.toString();
}
-
+
@Override
public void setValueAt(Object aValue, int rowIndex, int columnIndex) {
PresetsTableRow rowModel = elements.get(rowIndex);
// 無視する.
}
}
-
+
@Override
public Class<?> getColumnClass(int columnIndex) {
switch (columnIndex) {
}
return String.class;
}
-
+
@Override
public boolean isCellEditable(int rowIndex, int columnIndex) {
switch (columnIndex ) {
/**
* お勧めリンクのテーブルの行編集モデル
- *
+ *
* @author seraphy
*/
class RecommendationTableRow {
-
+
private RecommendationURL recommendationURL;
-
+
public RecommendationTableRow(RecommendationURL recommendationURL) {
if (recommendationURL == null) {
throw new IllegalArgumentException();
}
this.recommendationURL = recommendationURL.clone();
}
-
+
public String getLocalizedName() {
return recommendationURL.getDisplayName();
}
-
+
public void setLocalizedName(String localizedName) {
recommendationURL.setDisplayName(localizedName);
}
-
+
public String getURL() {
return recommendationURL.getUrl();
}
-
+
public void setURL(String url) {
recommendationURL.setUrl(url);
}
-
+
public RecommendationURL convert() {
return recommendationURL.clone();
}
/**
* お勧めリンクのテーブル編集モデル
- *
+ *
* @author seraphy
*/
class RecommendationTableModel extends AbstractTableModelWithComboBoxModel<RecommendationTableRow> {
-
+
private static final long serialVersionUID = 1L;
-
+
private static final Logger logger = Logger.getLogger(PartssetsTableModel.class.getName());
private static final String[] partssetsColumnNames;
-
+
private static final int[] partssetsColumnWidths;
-
+
static {
final Properties strings = LocalizedResourcePropertyLoader
.getCachedInstance().getLocalizedProperties(ProfileEditDialog.STRINGS_RESOURCE);
public RecommendationTableModel() {
}
-
+
public void adjustColumnModel(TableColumnModel columnModel) {
for (int idx = 0; idx < partssetsColumnWidths.length; idx++) {
columnModel.getColumn(idx).setPreferredWidth(partssetsColumnWidths[idx]);
}
}
-
+
public void addNew() {
addRow(new RecommendationTableRow(new RecommendationURL()));
}
-
+
public int getColumnCount() {
return partssetsColumnNames.length;
}
-
+
@Override
public String getColumnName(int column) {
return partssetsColumnNames[column];
}
-
-
+
+
public Object getValueAt(int rowIndex, int columnIndex) {
RecommendationTableRow rowModel = elements.get(rowIndex);
switch (columnIndex) {
return null;
}
}
-
+
@Override
public void setValueAt(Object aValue, int rowIndex, int columnIndex) {
RecommendationTableRow rowModel = elements.get(rowIndex);
// 無視する.
}
}
-
+
@Override
public Class<?> getColumnClass(int columnIndex) {
switch (columnIndex) {
}
return String.class;
}
-
+
@Override
public boolean isCellEditable(int rowIndex, int columnIndex) {
switch (columnIndex ) {