From 9ca046cd50f751f9424d8657f593c3d3e10ab351 Mon Sep 17 00:00:00 2001 From: Xoriun Date: Sat, 23 Apr 2022 12:33:50 +0200 Subject: [PATCH] Release of version v3.1 - Improvements to color changes while the tool is running. - Finalized the new file system. --- settings.xml | 8 +- src/edit/CellEditDialog.java | 859 ++++++++++++++++------------- src/edit/SectionManagerDialog.java | 47 +- src/gui/Abbreviations.java | 23 +- src/gui/ColorSettingProfile.java | 2 +- src/gui/ColorSettings.java | 69 +-- src/gui/GuiHelper.java | 23 +- src/gui/MainGui.java | 86 +-- src/gui/MenuItems.java | 3 - src/logic/AddRemoveControl.java | 23 +- src/logic/Cell.java | 35 +- src/logic/FileOperations.java | 221 ++------ src/logic/Hotkeys.java | 37 -- src/logic/MouseAdapters.java | 61 +- src/logic/PopupMenues.java | 12 +- src/logic/Row.java | 188 ++++--- src/logic/Section.java | 69 +-- 17 files changed, 860 insertions(+), 906 deletions(-) diff --git a/settings.xml b/settings.xml index f9b837b..1cf40a9 100644 --- a/settings.xml +++ b/settings.xml @@ -1,6 +1,6 @@ - H:\Gaming\Factorio\any%_Nefrums - Kopie.txt + H:\Gaming\Factorio\any%_Nefrums_import.xml Light @@ -16,9 +16,9 @@ Custom - -1 - -1 - -1 + -16776961 + -16711936 + -65536 diff --git a/src/edit/CellEditDialog.java b/src/edit/CellEditDialog.java index 49d0ee2..16e33a9 100644 --- a/src/edit/CellEditDialog.java +++ b/src/edit/CellEditDialog.java @@ -41,148 +41,148 @@ import logic.FileOperations; import logic.Cell.CellLabel; -public class CellEditDialog +public class CellEditDialog extends JDialog { - private static JDialog cellEditDialog; + /** automatically generated serialVerionUID */ + private static final long serialVersionUID = 6948924554417094355L; - private static Cell selectedCell; - private static EditPanel selectedCellPanel; - private static ArrayList editPanels = new ArrayList(); + private Cell selectedCell; + private EditPanel selectedCellPanel; + private ArrayList editPanels = new ArrayList(); - private static JPanel contentPanel; - private static JPanel actionsPanel; + private JPanel contentPanel; + private JPanel actionsPanel; - private static JPanel mainPanel; - private static JPanel contentScrollPanel; - private static JPanel actionsScrollPanel; + private JPanel mainPanel; + private JPanel contentScrollPanel; + private JPanel actionsScrollPanel; - private static JPanel contentEditLabelPanel; - private static JPanel actionsEditPanel; + private JPanel contentEditLabelPanel; + private JPanel actionsEditPanel; - private static JButton buttonSplitAtCursor; - private static JButton buttonEditIcon; + private JButton buttonSplitAtCursor; + private JButton buttonEditIcon; - private static ArrayList > actionComboboxList = new ArrayList >(); - private static ArrayList actionTextfieldList = new ArrayList(); + private ArrayList> actionComboboxList = new ArrayList>(); + private ArrayList actionTextfieldList = new ArrayList(); - private static String[] possibleActionsArray = new String[] {"", "text_to_clipboard", "file_to_clipboard"}; + private String[] possibleActionsArray = new String[] { "", "text_to_clipboard", "file_to_clipboard" }; - private static boolean iconEditorOpen = false; + private String[] abbreviationsAndFileNamesList = new String[0]; - private static String[] abbreviationsAndFileNamesList; + private IconEditDialog iconEditDialog; + private static JPanel innerPanel; // need in order to change the color of the spacing border in the iconEditDialog - public static void initializeCellEditDialog() + public CellEditDialog() { - cellEditDialog = new JDialog(MainGui.window); - cellEditDialog.setTitle("Cell Manager"); - cellEditDialog.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE); - cellEditDialog.addWindowListener(new WindowAdapter() + this.setTitle("Cell Manager"); + this.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE); + this.addWindowListener(new WindowAdapter() { + @Override + public void windowClosing(WindowEvent e) { - @Override - public void windowClosing(WindowEvent e) - { - hideEditDialog(); - } + hideEditDialog(); } - ); + }); + iconEditDialog = this.new IconEditDialog(this); mainPanel = new JPanel(); // main panel for the JDialog - JPanel cell_panel = new JPanel(); // panel that contains the content and action editing of the cell - contentPanel = new JPanel(); // panel that contains the content editing (text and icons) of the cell - JScrollPane cellLabel_scroll_pane = new JScrollPane( // ScrollPane for the content edit - JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, - JScrollPane.HORIZONTAL_SCROLLBAR_NEVER); - contentScrollPanel = new JPanel(); // panel within the scroll panel (its only purpose is to add a BorderLayout so the textboxes don't stretch vertically) - contentEditLabelPanel = new JPanel(); // panel for the EditPanels which represent the different text and icon labels - JPanel control_cellLabel_panel = new JPanel(); // panel for the edit buttons - actionsPanel = new JPanel(); // panel that contains the action editing of the cell - JScrollPane actions_scroll_pane = new JScrollPane( // ScrollPane for the actions edit - JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, - JScrollPane.HORIZONTAL_SCROLLBAR_NEVER); - actionsScrollPanel = new JPanel(); // panel within the scroll panel (its only purpose is to add a BorderLayout so the textboxes don't stretch vertically) - actionsEditPanel = new JPanel(); // panel for the actions edit - JPanel main_control_panel = new JPanel(); // panel for the main control buttons + JPanel cell_panel = new JPanel(); // panel that contains the content and action editing of the cell + contentPanel = new JPanel(); // panel that contains the content editing (text and icons) of the cell + JScrollPane cellLabel_scroll_pane = new JScrollPane( // ScrollPane for the content edit + JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, + JScrollPane.HORIZONTAL_SCROLLBAR_NEVER); + contentScrollPanel = new JPanel(); // panel within the scroll panel (its only purpose is to add a BorderLayout so the textboxes don't stretch vertically) + contentEditLabelPanel = new JPanel(); // panel for the EditPanels which represent the different text and icon labels + JPanel control_cellLabel_panel = new JPanel(); // panel for the edit buttons + actionsPanel = new JPanel(); // panel that contains the action editing of the cell + JScrollPane actions_scroll_pane = new JScrollPane( // ScrollPane for the actions edit + JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, + JScrollPane.HORIZONTAL_SCROLLBAR_NEVER); + actionsScrollPanel = new JPanel(); // panel within the scroll panel (its only purpose is to add a BorderLayout so the textboxes don't stretch vertically) + actionsEditPanel = new JPanel(); // panel for the actions edit + JPanel main_control_panel = new JPanel(); // panel for the main control buttons - mainPanel.setLayout(new BorderLayout() ); - mainPanel.setBackground(ColorSettings.getBackgroundColor() ); - mainPanel.setPreferredSize(new Dimension(300, 500) ); - mainPanel.setBorder(GuiHelper.getDialogBorder() ); + mainPanel.setLayout(new BorderLayout()); + mainPanel.setBackground(ColorSettings.getBackgroundColor()); + mainPanel.setPreferredSize(new Dimension(300, 500)); + mainPanel.setBorder(GuiHelper.getDialogBorder()); mainPanel.add(cell_panel, BorderLayout.CENTER); mainPanel.add(main_control_panel, BorderLayout.PAGE_END); - - cell_panel.setLayout(new BorderLayout() ); + + cell_panel.setLayout(new BorderLayout()); cell_panel.setOpaque(false); - cell_panel.add(contentPanel, BorderLayout.CENTER); + cell_panel.add(contentPanel, BorderLayout.CENTER); cell_panel.add(actionsPanel, BorderLayout.PAGE_END); - contentPanel.setLayout(new BorderLayout() ); + contentPanel.setLayout(new BorderLayout()); contentPanel.setOpaque(false); - contentPanel.setBorder(GuiHelper.getTitledBorderWithCorrectTextColor("Content") ); + contentPanel.setBorder(GuiHelper.getTitledBorderWithCorrectTextColor("Content")); contentPanel.add(cellLabel_scroll_pane, BorderLayout.CENTER); contentPanel.add(control_cellLabel_panel, BorderLayout.LINE_END); cellLabel_scroll_pane.setOpaque(false); - cellLabel_scroll_pane.setBorder(GuiHelper.getEmptyBorder() ); + cellLabel_scroll_pane.setBorder(GuiHelper.getEmptyBorder()); cellLabel_scroll_pane.getViewport().add(contentScrollPanel); cellLabel_scroll_pane.getVerticalScrollBar().setUnitIncrement(16); - contentScrollPanel.setLayout(new BorderLayout() ); - contentScrollPanel.setBackground(ColorSettings.getBackgroundColor() ); + contentScrollPanel.setLayout(new BorderLayout()); + contentScrollPanel.setBackground(ColorSettings.getBackgroundColor()); contentScrollPanel.add(contentEditLabelPanel, BorderLayout.PAGE_START); - contentEditLabelPanel.setLayout(new BoxLayout(contentEditLabelPanel, BoxLayout.Y_AXIS) ); + contentEditLabelPanel.setLayout(new BoxLayout(contentEditLabelPanel, BoxLayout.Y_AXIS)); contentEditLabelPanel.setOpaque(false); - control_cellLabel_panel.setLayout(new BoxLayout(control_cellLabel_panel, BoxLayout.Y_AXIS) ); + control_cellLabel_panel.setLayout(new BoxLayout(control_cellLabel_panel, BoxLayout.Y_AXIS)); control_cellLabel_panel.setOpaque(false); buttonSplitAtCursor = new JButton("Split at cursor"); buttonSplitAtCursor.setAlignmentX(0.5f); - buttonSplitAtCursor.addActionListener(getSplitAtCurserListener() ); + buttonSplitAtCursor.addActionListener(getSplitAtCurserListener()); control_cellLabel_panel.add(buttonSplitAtCursor); buttonEditIcon = new JButton("Edit icon"); buttonEditIcon.setAlignmentX(0.5f); - buttonEditIcon.addActionListener(getIconEditListener() ); + buttonEditIcon.addActionListener(getIconEditListener()); control_cellLabel_panel.add(buttonEditIcon); JButton button_remove = new JButton("Remove"); button_remove.setAlignmentX(0.5f); - button_remove.addActionListener(getRemoveEditPanelListener() ); + button_remove.addActionListener(getRemoveEditPanelListener()); control_cellLabel_panel.add(button_remove); JButton button_add_above = new JButton("Add above"); button_add_above.setAlignmentX(0.5f); - button_add_above.addActionListener(getAddAboveListener() ); + button_add_above.addActionListener(getAddAboveListener()); control_cellLabel_panel.add(button_add_above); JButton button_add_below = new JButton("Add below"); button_add_below.setAlignmentX(0.5f); - button_add_below.addActionListener(getAddBelowPanelListener() ); + button_add_below.addActionListener(getAddBelowPanelListener()); control_cellLabel_panel.add(button_add_below); JButton button_add__linebreak_below = new JButton("Add Linebreak"); button_add__linebreak_below.setAlignmentX(0.5f); - button_add__linebreak_below.addActionListener(getAddLineBreakBelowListener() ); + button_add__linebreak_below.addActionListener(getAddLineBreakBelowListener()); control_cellLabel_panel.add(button_add__linebreak_below); - actionsPanel.setLayout(new BorderLayout() ); - actionsPanel.setBorder(GuiHelper.getTitledBorderWithCorrectTextColor("Actions") ); - actionsPanel.setPreferredSize(new Dimension(1000, 150) ); + actionsPanel.setLayout(new BorderLayout()); + actionsPanel.setBorder(GuiHelper.getTitledBorderWithCorrectTextColor("Actions")); + actionsPanel.setPreferredSize(new Dimension(1000, 150)); actionsPanel.setOpaque(false); actionsPanel.add(actions_scroll_pane, BorderLayout.CENTER); actions_scroll_pane.setOpaque(false); - actions_scroll_pane.setBorder(GuiHelper.getEmptyBorder() ); + actions_scroll_pane.setBorder(GuiHelper.getEmptyBorder()); actions_scroll_pane.getViewport().add(actionsScrollPanel); actions_scroll_pane.getVerticalScrollBar().setUnitIncrement(16); - actionsScrollPanel.setLayout(new FlowLayout() ); - actionsScrollPanel.setBackground(ColorSettings.getBackgroundColor() ); + actionsScrollPanel.setLayout(new FlowLayout()); + actionsScrollPanel.setBackground(ColorSettings.getBackgroundColor()); actionsScrollPanel.add(actionsEditPanel, BorderLayout.PAGE_START); - actionsEditPanel.setLayout(new GridBagLayout() ); + actionsEditPanel.setLayout(new GridBagLayout()); actionsEditPanel.setOpaque(false); actionsEditPanel.setAlignmentX(0f); @@ -192,43 +192,58 @@ public void windowClosing(WindowEvent e) JButton confirmButton = new JButton("Confirm"); JButton cancel_button = new JButton("Cancel"); - confirmButton.addActionListener(e -> {saveCell(); hideEditDialog(); } ); - cancel_button.addActionListener(e -> {hideEditDialog(); } ); + confirmButton.addActionListener(e -> { + saveCell(); + hideEditDialog(); + }); + cancel_button.addActionListener(e -> { + hideEditDialog(); + }); main_control_panel.add(confirmButton); main_control_panel.add(cancel_button); - cellEditDialog.add(mainPanel); - cellEditDialog.pack(); - cellEditDialog.setVisible(false); + this.add(mainPanel); + this.pack(); + this.setVisible(false); } - public static void updateColorSettings() + public void updateLightingSettings() { - contentPanel.setBorder(GuiHelper.getTitledBorderWithCorrectTextColor("Content") ); - actionsPanel.setBorder(GuiHelper.getTitledBorderWithCorrectTextColor("Actions") ); + contentPanel.setBorder(GuiHelper.getTitledBorderWithCorrectTextColor("Content")); + actionsPanel.setBorder(GuiHelper.getTitledBorderWithCorrectTextColor("Actions")); - mainPanel.setBackground(ColorSettings.getBackgroundColor() ); - contentScrollPanel.setBackground(ColorSettings.getBackgroundColor() ); - actionsScrollPanel.setBackground(ColorSettings.getBackgroundColor() ); + mainPanel.setBackground(ColorSettings.getBackgroundColor()); + contentScrollPanel.setBackground(ColorSettings.getBackgroundColor()); + actionsScrollPanel.setBackground(ColorSettings.getBackgroundColor()); updateEditPanels(); updateActionsEdit(); + + if (iconEditDialog != null) + { + innerPanel.setBorder(GuiHelper.getSpacingBorder(5)); + for (Component comp : GuiHelper.getAllComponents(iconEditDialog)) + { + comp.setBackground(ColorSettings.getBackgroundColor() ); + comp.setForeground(ColorSettings.getTextColor() ); + } + } } - private static void saveCell() + private void saveCell() { String new_content_string = ""; - for (EditPanel edit_panel: editPanels) + for (EditPanel edit_panel : editPanels) new_content_string += edit_panel.getString(); String new_action_string = getActionsString(); String new_cell_string = new_content_string + (new_action_string.isEmpty() ? "" : ">>" + new_action_string); - if ( !new_cell_string.equals(selectedCell.getCellString() ) ) + if (!new_cell_string.equals(selectedCell.getCellString())) { // updating content of section - selectedCell.updateCell(new_cell_string); + selectedCell.updateCell(new_cell_string); // reorganizing gui MainGui.spaceColums(); @@ -236,32 +251,36 @@ private static void saveCell() } } - private static String getActionsString() + private String getActionsString() { String res = ""; for (int i = 0; i < actionComboboxList.size(); i ++) { - if (actionComboboxList.get(i).getSelectedItem().equals("") ) continue; + if (actionComboboxList.get(i).getSelectedItem().equals("")) + continue; res += actionComboboxList.get(i).getSelectedItem() + ":" + actionTextfieldList.get(i).getText() + "#"; } return res.equals("") ? res : res.substring(0, res.length() - 1); } - public static void hideEditDialog() + public void hideEditDialog() { if (selectedCell != null) { selectedCell.setDefaultBorder(); selectedCell = null; } - cellEditDialog.setVisible(false); + this.setVisible(false); + if (iconEditDialog != null) + iconEditDialog.setVisible(false); + return; } - public static void processCell(Cell cell) + public void processCell(Cell cell) { - if (iconEditorOpen) - return; + if (iconEditDialog != null) + iconEditDialog.setVisible(false); // cell if (selectedCell != null) @@ -277,7 +296,7 @@ public static void processCell(Cell cell) contentEditLabelPanel.removeAll(); editPanels.clear(); - for (CellLabel cell_label : cell.getCellLabels() ) + for (CellLabel cell_label : cell.getCellLabels()) { EditPanel edit_panel = cell_label.getEditPanel(); addMosueLisetenerToEditPanel(edit_panel); @@ -286,7 +305,7 @@ public static void processCell(Cell cell) // Add lineBreaks int index = 0; // position in 'editPanles' where a linebreak has to be added - String[] lines = cell.getCellString().split(Pattern.quote("\\n") ); + String[] lines = cell.getCellString().split(Pattern.quote("\\n")); for (int i = 0; i < lines.length - 1; i ++) // skip last line, no linebreak needed there { String line = lines[i]; @@ -301,10 +320,10 @@ public static void processCell(Cell cell) actionsEditPanel.removeAll(); actionComboboxList.clear(); actionTextfieldList.clear(); - for (String[] action : cell.getActionsArray() ) + for (String[] action : cell.getActionsArray()) { JComboBox comboBox = new JComboBox(possibleActionsArray); - comboBox.setSelectedItem(action[0] ); + comboBox.setSelectedItem(action[0]); JTextField textField = new JTextField(action[1], 15); actionComboboxList.add(comboBox); @@ -314,15 +333,15 @@ public static void processCell(Cell cell) updateEditPanels(); updateActionsEdit(); - processEditPanel(editPanels.get(0) ); + processEditPanel(editPanels.get(0)); // Dialog - cellEditDialog.setTitle(cell.getInfo() ); - cellEditDialog.pack(); - cellEditDialog.setVisible(true); + this.setTitle(cell.getInfo()); + this.pack(); + this.setVisible(true); } - private static void updateActionsEdit() + private void updateActionsEdit() { actionsEditPanel.removeAll(); GridBagConstraints gbc = new GridBagConstraints(); @@ -330,10 +349,11 @@ private static void updateActionsEdit() for (int index = 0; index < actionComboboxList.size(); index ++) { JLabel remove_label = new JLabel(" - "); - remove_label.setForeground(ColorSettings.getTextColor() ); + remove_label.setForeground(ColorSettings.getTextColor()); remove_label.setOpaque(false); remove_label.addMouseListener(new MouseAdapter() { final int index = gbc.gridy; + @Override public void mouseClicked(MouseEvent me) { @@ -355,22 +375,23 @@ public void mouseClicked(MouseEvent me) gbc.gridx = 1; JLabel add_label = new JLabel("+"); - add_label.setForeground(ColorSettings.getTextColor() ); + add_label.setForeground(ColorSettings.getTextColor()); add_label.setOpaque(false); add_label.addMouseListener(new MouseAdapter() { @Override - public void mouseClicked(MouseEvent me) { - actionComboboxList.add(new JComboBox(possibleActionsArray) ); - actionTextfieldList.add(new JTextField(15) ); + public void mouseClicked(MouseEvent me) + { + actionComboboxList.add(new JComboBox(possibleActionsArray)); + actionTextfieldList.add(new JTextField(15)); updateActionsEdit(); } }); actionsEditPanel.add(add_label, gbc); - cellEditDialog.pack(); + this.pack(); } - private static void addMosueLisetenerToEditPanel(EditPanel edit_panel) + private void addMosueLisetenerToEditPanel(EditPanel edit_panel) { edit_panel.addMouseListener(new MouseInputAdapter() { @Override @@ -381,10 +402,10 @@ public void mouseClicked(MouseEvent e) }); } - private static void processEditPanel(EditPanel edit_panel) + private void processEditPanel(EditPanel edit_panel) { - if (iconEditorOpen) - return; + if (iconEditDialog != null) + iconEditDialog.setVisible(false); if (selectedCellPanel != null) selectedCellPanel.setDefaultBorder(); @@ -395,33 +416,33 @@ private static void processEditPanel(EditPanel edit_panel) buttonEditIcon.setEnabled(selectedCellPanel instanceof EditIconLabel); } - private static void updateEditPanels() + private void updateEditPanels() { contentEditLabelPanel.removeAll(); for (EditPanel edit_panel : editPanels) { edit_panel.updateColorSettings(); - contentEditLabelPanel.add( (Component) edit_panel); + contentEditLabelPanel.add((Component) edit_panel); } - cellEditDialog.pack(); + this.pack(); } - private static ActionListener getSplitAtCurserListener() + private ActionListener getSplitAtCurserListener() { return new ActionListener() { @Override public void actionPerformed(ActionEvent e) { - int caret_position = ( (EditTextField) selectedCellPanel).getCaretPosition(); - String content = ( (EditTextField) selectedCellPanel).getText(); - if (caret_position > 0 && caret_position < content.length() ) + int caret_position = ((EditTextField) selectedCellPanel).getCaretPosition(); + String content = ((EditTextField) selectedCellPanel).getText(); + if (caret_position > 0 && caret_position < content.length()) { int selected_index = editPanels.indexOf(selectedCellPanel); editPanels.remove(selectedCellPanel); - EditTextField new_edit_text_field_1 = new EditTextField(content.substring(0, caret_position) ); - EditTextField new_edit_text_field_2 = new EditTextField(content.substring(caret_position) ); + EditTextField new_edit_text_field_1 = new EditTextField(content.substring(0, caret_position)); + EditTextField new_edit_text_field_2 = new EditTextField(content.substring(caret_position)); addMosueLisetenerToEditPanel(new_edit_text_field_1); addMosueLisetenerToEditPanel(new_edit_text_field_2); @@ -437,247 +458,19 @@ public void actionPerformed(ActionEvent e) }; } - private static ActionListener getIconEditListener() + private ActionListener getIconEditListener() { return new ActionListener() { - String main_image_abbr; - String layered_image_abbr; - - JLabel main_image_label; - JLabel layered_image_label; - - Dimension combobox_main_dim, combobox_layered_dim; - - private void closeDialog(JDialog dialog) - { - iconEditorOpen = false; - dialog.dispose(); - } - @Override - public void actionPerformed(ActionEvent ae) + public void actionPerformed(ActionEvent e) { - updateAbbreviationsAndFileNamesList(); - - iconEditorOpen = true; - - main_image_abbr = ( (EditIconLabel) selectedCellPanel).getMainImageAbbr(); - layered_image_abbr = ( (EditIconLabel) selectedCellPanel).getLayeredImageAbbr(); - - JDialog icon_dialog = new JDialog(CellEditDialog.cellEditDialog, "Edit cell icon"); - icon_dialog.setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE); - icon_dialog.addWindowListener(new WindowAdapter() { @Override public void windowClosing(WindowEvent e) { closeDialog(icon_dialog); } } ); - - JPanel main_panel = new JPanel(); - main_panel.setBackground(ColorSettings.getBackgroundColor() ); - main_panel.setBorder(GuiHelper.getDialogBorder() ); - icon_dialog.add(main_panel); - - JPanel inner_panel = new JPanel(new BorderLayout() ); - inner_panel.setOpaque(false); - inner_panel.setBorder(GuiHelper.getSpacingBorder(5) ); - main_panel.add(inner_panel); - - JPanel content_panel = new JPanel(new GridBagLayout() ); - content_panel.setOpaque(false); - inner_panel.add(content_panel, BorderLayout.CENTER); - GridBagConstraints gbc = new GridBagConstraints(); - gbc.insets = new Insets(0, 0, 2, 2); - gbc.fill = GridBagConstraints.BOTH; - - // main image - - //label - gbc.gridy = gbc.gridx = 0; - content_panel.add(GuiHelper.getAlignedNonOpaqueJLabelWithCurrentColors("Main image", GuiHelper.LEFT), gbc); - - //image - gbc.gridx ++; - main_image_label = new JLabel(GuiHelper.getScaledImageIconFromAbbreviation(main_image_abbr) ); - content_panel.add(main_image_label, gbc); - - //edit panel - gbc.gridx ++; - JPanel main_image_edit_panel = new JPanel(); - main_image_edit_panel.setLayout(new GridBagLayout() ); - main_image_edit_panel.setOpaque(false); - GridBagConstraints gbc_main = new GridBagConstraints(); - gbc_main.insets = new Insets(2, 2, 2, 2); - gbc_main.fill = GridBagConstraints.HORIZONTAL; - gbc_main.gridx = gbc_main.gridy = 0; - - main_image_edit_panel.add(GuiHelper.getAlignedNonOpaqueJLabelWithCurrentColors("List:", GuiHelper.LEFT), gbc_main); - - gbc_main.gridx ++; - JComboBox combobox_main = new JComboBox(abbreviationsAndFileNamesList); - combobox_main.setSelectedItem(getLowercaseStringWithFirstCharCapitablized(main_image_abbr) ); - main_image_edit_panel.add(combobox_main, gbc_main); - - gbc_main.gridy ++; - gbc_main.gridx = 0; - main_image_edit_panel.add(GuiHelper.getAlignedNonOpaqueJLabelWithCurrentColors("Filter:", GuiHelper.LEFT), gbc_main); - - gbc_main.gridx ++; - JTextField filter_textFiled_main = new JTextField(); - main_image_edit_panel.add(filter_textFiled_main, gbc_main); - - combobox_main.addActionListener(new ActionListener() { - @Override - public void actionPerformed(ActionEvent e) - { - main_image_abbr = (String) combobox_main.getSelectedItem(); - main_image_label.setIcon(GuiHelper.getScaledImageIconFromAbbreviation(main_image_abbr) ); - icon_dialog.pack(); - } - }); - filter_textFiled_main.getDocument().addDocumentListener(new DocumentListener() { - @Override public void removeUpdate(DocumentEvent e) { update(); } - @Override public void insertUpdate(DocumentEvent e) { update(); } - @Override public void changedUpdate(DocumentEvent e) { update(); } - - private void update() - { - combobox_main.setModel(new DefaultComboBoxModel<>(getFilteredAbbreviationsAndFileNamesList(filter_textFiled_main.getText() ) ) ); - combobox_main.setPreferredSize(combobox_main_dim); - } - }); - - content_panel.add(main_image_edit_panel, gbc); - - // layered? - - //label - gbc.gridy ++; - gbc.gridx = 0; - content_panel.add(GuiHelper.getAlignedNonOpaqueJLabelWithCurrentColors("Layered image", GuiHelper.LEFT), gbc); - - //check box - gbc.gridx ++; - JCheckBox checkbox_layered = new JCheckBox(); - checkbox_layered.setSelected( ! layered_image_abbr.equals("") ); - checkbox_layered.setOpaque(false); - content_panel.add(checkbox_layered, gbc); - - // layered image - - //label - gbc.gridy ++; - gbc.gridx = 0; - content_panel.add(GuiHelper.getAlignedNonOpaqueJLabelWithCurrentColors("Layered image", GuiHelper.LEFT), gbc); - - //image - gbc.gridx ++; - layered_image_label = layered_image_abbr.isEmpty() ? new JLabel() : new JLabel(GuiHelper.getScaledImageIconFromAbbreviation(layered_image_abbr) ); - content_panel.add(layered_image_label, gbc); - - //edit pane; - - gbc.gridx ++; - JPanel layered_image_edit_panel = new JPanel(); - layered_image_edit_panel.setLayout(new GridBagLayout() ); - layered_image_edit_panel.setOpaque(false); - GridBagConstraints gbc_layered = new GridBagConstraints(); - gbc_layered.insets = new Insets(2, 2, 2, 2); - gbc_layered.fill = GridBagConstraints.HORIZONTAL; - gbc_layered.gridx = gbc_layered.gridy = 0; - - layered_image_edit_panel.add(GuiHelper.getAlignedNonOpaqueJLabelWithCurrentColors("List:", GuiHelper.LEFT), gbc_layered); - - gbc_layered.gridx ++; - JComboBox combobox_layered = new JComboBox(abbreviationsAndFileNamesList); - combobox_layered.setSelectedItem(getLowercaseStringWithFirstCharCapitablized(layered_image_abbr) ); - layered_image_edit_panel.add(combobox_layered, gbc_layered); - - gbc_layered.gridx = 0; - gbc_layered.gridy ++; - layered_image_edit_panel.add(GuiHelper.getAlignedNonOpaqueJLabelWithCurrentColors("Filter:", GuiHelper.LEFT), gbc_layered); - - gbc_layered.gridx ++; - JTextField filter_textFiled_layered = new JTextField(); - layered_image_edit_panel.add(filter_textFiled_layered, gbc_layered); - - content_panel.add(layered_image_edit_panel, gbc); - - combobox_layered.addActionListener(new ActionListener() { - @Override - public void actionPerformed(ActionEvent e) - { - layered_image_abbr = (String) combobox_layered.getSelectedItem(); - content_panel.remove(layered_image_label); - layered_image_label = new JLabel(GuiHelper.getScaledImageIconFromAbbreviation(layered_image_abbr) ); - gbc.gridx = 1; - gbc.gridy = 2; - content_panel.add(layered_image_label, gbc); - icon_dialog.pack(); - } - }); - filter_textFiled_layered.getDocument().addDocumentListener(new DocumentListener() { - @Override public void removeUpdate(DocumentEvent e) { update(); } - @Override public void insertUpdate(DocumentEvent e) { update(); } - @Override public void changedUpdate(DocumentEvent e) { update(); } - - private void update() - { - combobox_layered.setModel(new DefaultComboBoxModel<>(getFilteredAbbreviationsAndFileNamesList(filter_textFiled_layered.getText() ) ) ); - combobox_layered.setPreferredSize(combobox_layered_dim); - } - }); - - // horizontal alignment - gbc.gridy ++; - gbc.gridx = 0; - content_panel.add(GuiHelper.getAlignedNonOpaqueJLabelWithCurrentColors("Horizontal alignment", GuiHelper.LEFT), gbc); - - gbc.gridx ++; - JComboBox dropdown_horizontal = new JComboBox(new String[] {"left", "center", "right"} ); - dropdown_horizontal.setSelectedItem( ( (EditIconLabel) selectedCellPanel).getLayeredHorizontalAlignment() ); - gbc.fill = GridBagConstraints.HORIZONTAL; - content_panel.add(dropdown_horizontal, gbc); - gbc.fill = GridBagConstraints.BOTH; - - // vertical alignment - gbc.gridy ++; - gbc.gridx = 0; - content_panel.add(GuiHelper.getAlignedNonOpaqueJLabelWithCurrentColors("Vertical alignment", GuiHelper.LEFT), gbc); - - gbc.gridx ++; - JComboBox dropdown_vertical = new JComboBox(new String[] {"top", "center", "bottom"} ); - dropdown_vertical.setSelectedItem( ( (EditIconLabel) selectedCellPanel).getLayeredVerticalAlignment() ); - gbc.fill = GridBagConstraints.HORIZONTAL; - content_panel.add(dropdown_vertical, gbc); - gbc.fill = GridBagConstraints.BOTH; - - // controls - JPanel control_panel = new JPanel(); - control_panel.setOpaque(false); - inner_panel.add(control_panel, BorderLayout.PAGE_END); - - JButton button_confirm = new JButton("Confirm"); - control_panel.add(button_confirm); - button_confirm.addActionListener(e -> { - if (checkbox_layered.isSelected() ) - ( (EditIconLabel) selectedCellPanel).updateIcon(main_image_abbr, layered_image_abbr, (String) dropdown_vertical.getSelectedItem(), (String) dropdown_horizontal.getSelectedItem() ); - else - ( (EditIconLabel) selectedCellPanel).updateIcon(main_image_abbr); - CellEditDialog.cellEditDialog.pack(); - closeDialog(icon_dialog); - }); - - JButton button_cancel = new JButton("Cancel"); - control_panel.add(button_cancel); - button_cancel.addActionListener(e -> closeDialog(icon_dialog) ); - - icon_dialog.pack(); - icon_dialog.setVisible(true); - - combobox_main_dim = combobox_main.getSize(); - combobox_layered_dim = combobox_layered.getSize(); + iconEditDialog.updateIconEditDialog(); } }; } - private static ActionListener getRemoveEditPanelListener() + private ActionListener getRemoveEditPanelListener() { return new ActionListener() { @@ -691,7 +484,7 @@ public void actionPerformed(ActionEvent e) editPanels.remove(selectedCellPanel); - if (selected_index >= editPanels.size() ) + if (selected_index >= editPanels.size()) selected_index = editPanels.size() - 1; selectedCellPanel = editPanels.get(selected_index); @@ -701,7 +494,7 @@ public void actionPerformed(ActionEvent e) }; } - private static ActionListener getAddAboveListener() + private ActionListener getAddAboveListener() { return new ActionListener() { @@ -721,7 +514,7 @@ public void actionPerformed(ActionEvent e) }; } - private static ActionListener getAddBelowPanelListener() + private ActionListener getAddBelowPanelListener() { return new ActionListener() { @@ -741,7 +534,7 @@ public void actionPerformed(ActionEvent e) }; } - private static ActionListener getAddLineBreakBelowListener() + private ActionListener getAddLineBreakBelowListener() { return new ActionListener() { @@ -763,36 +556,336 @@ public void actionPerformed(ActionEvent e) private static String getLowercaseStringWithFirstCharCapitablized(String str) { - return str.length() == 0 ? str : str.length() == 1 ? str.toUpperCase() : Character.toUpperCase(str.charAt(0) ) + str.substring(1).toLowerCase(); + return str.length() == 0 ? str : str.length() == 1 ? str.toUpperCase() : Character.toUpperCase(str.charAt(0)) + str.substring(1).toLowerCase(); } - private static void updateAbbreviationsAndFileNamesList() + private void updateAbbreviationsAndFileNamesList() { - ArrayList completeNames = Abbreviations.getStreamOfCompleteNames().collect(Collectors.toCollection(ArrayList::new) ); - abbreviationsAndFileNamesList = Stream.concat( - Stream.concat(Stream.of(""), Abbreviations.getStreamOfAbbreviations() ), - FileOperations.getStreamOfNamesOfImagesInImagesDirectory() - .filter(e -> ! completeNames.contains(e) ) - .map(e -> getLowercaseStringWithFirstCharCapitablized(e) ) - ) - .map(e -> getLowercaseStringWithFirstCharCapitablized(e) ) - .sorted( (e,f) -> e.compareTo(f) ) - .toArray(String[]::new); + ArrayList completeNames = Abbreviations.getStreamOfCompleteNames().collect(Collectors.toCollection(ArrayList::new)); + abbreviationsAndFileNamesList = Stream + .concat(Stream.concat(Stream.of(""), Abbreviations.getStreamOfAbbreviations()), + FileOperations.getStreamOfNamesOfImagesInImagesDirectory().filter(e -> !completeNames.contains(e)).map(e -> getLowercaseStringWithFirstCharCapitablized(e))) + .map(e -> getLowercaseStringWithFirstCharCapitablized(e)).sorted((e, f) -> e.compareTo(f)).toArray(String[]::new); } - private static String[] getFilteredAbbreviationsAndFileNamesList(String filter) + private String[] getFilteredAbbreviationsAndFileNamesList(String filter) { - return Stream.of(abbreviationsAndFileNamesList) - .map(e -> e.toLowerCase() ) - .filter(e -> e.contains(filter.toLowerCase() ) ). - sorted( (String e, String f) -> { - boolean eStartsWith = e.startsWith(filter); - boolean fStartsWith = f.startsWith(filter); - if (eStartsWith && !fStartsWith) return -1; - else if ( !eStartsWith && fStartsWith) return 1; - else return e.compareTo(f); - } ) - .map(e -> getLowercaseStringWithFirstCharCapitablized(e) ) - .toArray(String[]::new); + return Stream.of(abbreviationsAndFileNamesList).map(e -> e.toLowerCase()).filter(e -> e.contains(filter.toLowerCase())).sorted((String e, String f) -> { + boolean eStartsWith = e.startsWith(filter); + boolean fStartsWith = f.startsWith(filter); + if (eStartsWith && !fStartsWith) + return -1; + else if (!eStartsWith && fStartsWith) + return 1; + else + return e.compareTo(f); + }).map(e -> getLowercaseStringWithFirstCharCapitablized(e)).toArray(String[]::new); + } + + private class IconEditDialog extends JDialog + { + /** auto-generated serialVersionUID */ + private static final long serialVersionUID = 5221541996676699472L; + private String main_image_abbr = ""; + private String layered_image_abbr = ""; + + private JLabel main_image_label; + private JLabel layered_image_label; + + private JComboBox combobox_main; + private JComboBox combobox_layered; + + private JTextField filter_textFiled_main; + private JTextField filter_textFiled_layered; + + private JCheckBox checkbox_layered; + + private JComboBox dropdown_horizontal, dropdown_vertical; + + private Dimension combobox_main_dim, combobox_layered_dim; + + private final GridBagConstraints gbc = new GridBagConstraints(); + + private void closeDialog() + { + iconEditDialog.setVisible(false); + } + + private void updateIconEditDialog() + { + updateAbbreviationsAndFileNamesList(); + + main_image_abbr = ((EditIconLabel) selectedCellPanel).getMainImageAbbr(); + layered_image_abbr = ((EditIconLabel) selectedCellPanel).getLayeredImageAbbr(); + + main_image_label.setIcon(GuiHelper.getScaledImageIconFromAbbreviation(main_image_abbr) ); + + if (layered_image_abbr.equals("") ) + { + checkbox_layered.setSelected(false); + layered_image_label.setIcon(null); + } + else + { + checkbox_layered.setSelected(true); + layered_image_label.setIcon(GuiHelper.getScaledImageIconFromAbbreviation(layered_image_abbr) ); + } + + + combobox_main.removeAllItems(); + for (String item : abbreviationsAndFileNamesList) + combobox_main.addItem(item); + combobox_main.setSelectedItem(getLowercaseStringWithFirstCharCapitablized(main_image_abbr)); + + combobox_layered.removeAllItems(); + for (String item : abbreviationsAndFileNamesList) + combobox_layered.addItem(item); + combobox_layered.setSelectedItem(getLowercaseStringWithFirstCharCapitablized(layered_image_abbr)); + + dropdown_horizontal.setSelectedItem(((EditIconLabel) selectedCellPanel).getLayeredHorizontalAlignment()); + dropdown_vertical.setSelectedItem(((EditIconLabel) selectedCellPanel).getLayeredVerticalAlignment()); + + this.pack(); + this.setVisible(true); + + combobox_main_dim = combobox_main.getSize(); + combobox_layered_dim = combobox_layered.getSize(); + } + + private IconEditDialog(JDialog cell_edit_dialog) + { + super(cell_edit_dialog, "Edit cell icon"); + + this.setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE); + this.addWindowListener(new WindowAdapter() { + @Override + public void windowClosing(WindowEvent e) + { + closeDialog(); + } + }); + + JPanel main_panel = new JPanel(); + main_panel.setBackground(ColorSettings.getBackgroundColor()); + main_panel.setBorder(GuiHelper.getDialogBorder()); + this.add(main_panel); + + innerPanel = new JPanel(new BorderLayout()); + innerPanel.setOpaque(false); + innerPanel.setBorder(GuiHelper.getSpacingBorder(5)); + main_panel.add(innerPanel); + + JPanel content_panel = new JPanel(new GridBagLayout()); + content_panel.setOpaque(false); + innerPanel.add(content_panel, BorderLayout.CENTER); + gbc.insets = new Insets(0, 0, 2, 2); + gbc.fill = GridBagConstraints.BOTH; + + // main image + + gbc.gridheight = 2; + + // label + gbc.gridy = gbc.gridx = 0; + content_panel.add(GuiHelper.getAlignedNonOpaqueJLabelWithCurrentColors("Main image", GuiHelper.LEFT), gbc); + + // image + gbc.gridx ++; + main_image_label = new JLabel(); + content_panel.add(main_image_label, gbc); + + gbc.gridheight = 1; + gbc.fill = GridBagConstraints.HORIZONTAL; + + // edit panel + gbc.gridx ++; + gbc.insets = new Insets(2, 2, 2, 2); + + content_panel.add(GuiHelper.getAlignedNonOpaqueJLabelWithCurrentColors("List:", GuiHelper.LEFT), gbc); + + gbc.gridx ++; + combobox_main = new JComboBox(); + content_panel.add(combobox_main, gbc); + + combobox_main.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) + { + if (e.getActionCommand().equals("comboBoxChanged") ) return; + main_image_abbr = (String) combobox_layered.getSelectedItem(); + main_image_label.setIcon(GuiHelper.getScaledImageIconFromAbbreviation(main_image_abbr) ); + iconEditDialog.pack(); + } + }); + + gbc.gridy ++; + gbc.gridx = 2; + content_panel.add(GuiHelper.getAlignedNonOpaqueJLabelWithCurrentColors("Filter:", GuiHelper.LEFT), gbc); + + gbc.gridx ++; + filter_textFiled_main = new JTextField(); + content_panel.add(filter_textFiled_main, gbc); + filter_textFiled_main.getDocument().addDocumentListener(new DocumentListener() { + @Override + public void removeUpdate(DocumentEvent e) + { + update(); + } + + @Override + public void insertUpdate(DocumentEvent e) + { + update(); + } + + @Override + public void changedUpdate(DocumentEvent e) + { + update(); + } + + private void update() + { + combobox_main.setModel(new DefaultComboBoxModel<>(getFilteredAbbreviationsAndFileNamesList(filter_textFiled_main.getText()))); + combobox_main.setPreferredSize(combobox_main_dim); + iconEditDialog.pack(); + } + }); + + // layered? + + gbc.insets = new Insets(0, 0, 2, 2); + gbc.fill = GridBagConstraints.BOTH; + + // label + gbc.gridy ++; + gbc.gridx = 0; + content_panel.add(GuiHelper.getAlignedNonOpaqueJLabelWithCurrentColors("Layered image", GuiHelper.LEFT), gbc); + + // check box + gbc.gridx ++; + checkbox_layered = new JCheckBox(); + checkbox_layered.setOpaque(false); + content_panel.add(checkbox_layered, gbc); + + // layered image + + gbc.gridheight = 2; + + // label + gbc.gridy ++; + gbc.gridx = 0; + content_panel.add(GuiHelper.getAlignedNonOpaqueJLabelWithCurrentColors("Layered image", GuiHelper.LEFT), gbc); + + // image + gbc.gridx ++; + layered_image_label = layered_image_abbr.isEmpty() ? new JLabel() : new JLabel(GuiHelper.getScaledImageIconFromAbbreviation(layered_image_abbr)); + content_panel.add(layered_image_label, gbc); + + // edit pane; + + gbc.gridheight = 1; + gbc.fill = GridBagConstraints.HORIZONTAL; + + gbc.gridx ++; + gbc.insets = new Insets(2, 2, 2, 2); + + content_panel.add(GuiHelper.getAlignedNonOpaqueJLabelWithCurrentColors("List:", GuiHelper.LEFT), gbc); + + gbc.gridx ++; + combobox_layered = new JComboBox(); + content_panel.add(combobox_layered, gbc); + + combobox_layered.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) + { + if (e.getActionCommand().equals("comboBoxChanged") ) return; + layered_image_abbr = (String) combobox_layered.getSelectedItem(); + layered_image_label.setIcon(GuiHelper.getScaledImageIconFromAbbreviation(layered_image_abbr) ); + iconEditDialog.pack(); + } + }); + + gbc.gridx = 2; + gbc.gridy ++; + content_panel.add(GuiHelper.getAlignedNonOpaqueJLabelWithCurrentColors("Filter:", GuiHelper.LEFT), gbc); + + gbc.gridx ++; + filter_textFiled_layered = new JTextField(); + content_panel.add(filter_textFiled_layered, gbc); + + filter_textFiled_layered.getDocument().addDocumentListener(new DocumentListener() { + @Override + public void removeUpdate(DocumentEvent e) + { + update(); + } + + @Override + public void insertUpdate(DocumentEvent e) + { + update(); + } + + @Override + public void changedUpdate(DocumentEvent e) + { + update(); + } + + private void update() + { + combobox_layered.setModel(new DefaultComboBoxModel<>(getFilteredAbbreviationsAndFileNamesList(filter_textFiled_layered.getText()))); + combobox_layered.setPreferredSize(combobox_layered_dim); + iconEditDialog.pack(); + } + }); + + // horizontal alignment + gbc.gridy ++; + gbc.gridx = 0; + content_panel.add(GuiHelper.getAlignedNonOpaqueJLabelWithCurrentColors("Horizontal alignment", GuiHelper.LEFT), gbc); + + gbc.gridx ++; + dropdown_horizontal = new JComboBox(new String[] { "left", "center", "right" }); + gbc.fill = GridBagConstraints.HORIZONTAL; + content_panel.add(dropdown_horizontal, gbc); + gbc.fill = GridBagConstraints.BOTH; + + // vertical alignment + gbc.gridy ++; + gbc.gridx = 0; + content_panel.add(GuiHelper.getAlignedNonOpaqueJLabelWithCurrentColors("Vertical alignment", GuiHelper.LEFT), gbc); + + gbc.gridx ++; + dropdown_vertical = new JComboBox(new String[] { "top", "center", "bottom" }); + gbc.fill = GridBagConstraints.HORIZONTAL; + content_panel.add(dropdown_vertical, gbc); + gbc.fill = GridBagConstraints.BOTH; + + // controls + JPanel control_panel = new JPanel(); + control_panel.setOpaque(false); + innerPanel.add(control_panel, BorderLayout.PAGE_END); + + JButton button_confirm = new JButton("Confirm"); + control_panel.add(button_confirm); + button_confirm.addActionListener(e -> { + if (checkbox_layered.isSelected()) + ((EditIconLabel) selectedCellPanel).updateIcon(main_image_abbr, layered_image_abbr, (String) dropdown_vertical.getSelectedItem(), (String) dropdown_horizontal.getSelectedItem()); + else + ((EditIconLabel) selectedCellPanel).updateIcon(main_image_abbr); + this.pack(); + closeDialog(); + }); + + JButton button_cancel = new JButton("Cancel"); + control_panel.add(button_cancel); + button_cancel.addActionListener(e -> closeDialog()); + + combobox_main_dim = combobox_main.getSize(); + combobox_layered_dim = combobox_layered.getSize(); + } } } \ No newline at end of file diff --git a/src/edit/SectionManagerDialog.java b/src/edit/SectionManagerDialog.java index 586d73e..740d52d 100644 --- a/src/edit/SectionManagerDialog.java +++ b/src/edit/SectionManagerDialog.java @@ -15,22 +15,23 @@ import logic.AddRemoveControl; import logic.MouseAdapters; -public class SectionManagerDialog +public class SectionManagerDialog extends JDialog { - public static JDialog sectionManagerDialog; - public static JPanel sectionManagerPanel; + /** Automatically generated secrialVerionUID */ + private static final long serialVersionUID = 4418008182269964040L; + private static JPanel sectionManagerPanel; - public static void initializeSectionDialog() + public SectionManagerDialog() { - sectionManagerDialog = new JDialog(MainGui.window); - sectionManagerDialog.setTitle("Section Manager"); - sectionManagerDialog.setDefaultCloseOperation(WindowConstants.HIDE_ON_CLOSE); - sectionManagerDialog.setVisible(false); + super(MainGui.window); + this.setTitle("Section Manager"); + this.setDefaultCloseOperation(WindowConstants.HIDE_ON_CLOSE); + this.setVisible(false); } - public static void updateSectionManagerDialog() + public void updateSectionManagerDialog() { - sectionManagerDialog.getContentPane().removeAll(); + this.getContentPane().removeAll(); sectionManagerPanel = new JPanel(); sectionManagerPanel.setBackground(ColorSettings.getBackgroundColor()); @@ -53,7 +54,6 @@ public static void updateSectionManagerDialog() label.addMouseListener(MouseAdapters.getEditSectionTitleAdapter(label, section_index) ); label.setBorder(GuiHelper.getDefaultBorder(section_index == 0, true) ); inner_panel.add(label, gbc); - MainGui.sectionLabels.add(label); section_index ++; gbc.gridy ++; @@ -63,12 +63,25 @@ public static void updateSectionManagerDialog() inner_panel.add(AddRemoveControl.createAddSectionControl(section_index), gbc); sectionManagerPanel.add(inner_panel); - sectionManagerDialog.add(sectionManagerPanel); + this.add(sectionManagerPanel); - sectionManagerDialog.pack(); - if (sectionManagerDialog.getHeight() > MainGui.screensize.height - 150) - sectionManagerDialog.setPreferredSize(new Dimension(sectionManagerDialog.getWidth() + 20, MainGui.screensize.height - 150) ); - sectionManagerDialog.pack(); - sectionManagerDialog.setVisible(true); + this.pack(); + if (this.getHeight() > MainGui.screensize.height - 150) + this.setPreferredSize(new Dimension(this.getWidth() + 20, MainGui.screensize.height - 150) ); + this.pack(); + this.setVisible(true); + } + + public void updateLightingMode() + { + //TODO + updateSectionManagerDialog(); + } + + public void updateEditMode() + { + this.updateSectionManagerDialog(); + this.setVisible(MainGui.inEditMode); + this.pack(); } } diff --git a/src/gui/Abbreviations.java b/src/gui/Abbreviations.java index 55eed27..13aa525 100644 --- a/src/gui/Abbreviations.java +++ b/src/gui/Abbreviations.java @@ -21,6 +21,7 @@ import org.w3c.dom.Document; import org.w3c.dom.Element; +import org.w3c.dom.NodeList; import gui.MainGui; import logic.FileOperations; @@ -164,7 +165,7 @@ public void mouseClicked(MouseEvent e) abbreviations_dialog.dispose(); textfield_list.remove(row); abbr_list_copy.remove(abbr); - showAbbreviationSettingsDialog(abbr_location, images_dir, getAbbreviationsListFromTextfiles(textfield_list) ); + showAbbreviationSettingsDialog(abbr_location, images_dir, getAbbreviationsListFromTextfields(textfield_list) ); } } ); gbc.gridx = 3; @@ -201,7 +202,7 @@ public void mouseClicked(MouseEvent e) abbreviations_dialog.dispose(); textfield_list.remove(new_row); abbr_list_copy.remove(new_abbr); - showAbbreviationSettingsDialog(abbr_location, images_dir, getAbbreviationsListFromTextfiles(textfield_list) ); + showAbbreviationSettingsDialog(abbr_location, images_dir, getAbbreviationsListFromTextfields(textfield_list) ); } } ); gbc.gridx = 3; @@ -233,7 +234,7 @@ public void mouseClicked(MouseEvent e) abbreviations_dialog.dispose(); FileOperations.unsavedChanges = true; PopupAlerts.createMissingImagesMessage = true; - setAbbreviationsList(getAbbreviationsListFromTextfiles(textfield_list) ); + setAbbreviationsList(getAbbreviationsListFromTextfields(textfield_list) ); FileOperations.imagesDirectory = images_dir; FileOperations.fileAbbreviations = abbr_location; FileOperations.saveAbbereviationsFile(); @@ -260,7 +261,12 @@ public static void setAbbreviationsList(ArrayList abbreviations_list) abbreviationsList = abbreviations_list.stream().sorted( (a,b) -> {return a[0].compareTo(b[0] ); } ).collect(Collectors.toCollection(ArrayList::new) ); } - private static ArrayList getAbbreviationsListFromTextfiles(ArrayList textfields) + private static void sortAbbreviationList() + { + abbreviationsList = abbreviationsList.stream().sorted( (a,b) -> {return a[0].compareTo(b[0] ); } ).collect(Collectors.toCollection(ArrayList::new) ); + } + + private static ArrayList getAbbreviationsListFromTextfields(ArrayList textfields) { return textfields.stream().map(row -> new String[] {row[0].getText(), row[1].getText() } ).collect(Collectors.toCollection(ArrayList::new) ); } @@ -315,6 +321,15 @@ public static Element getAbbreviationsElement(Document doc) public static void parseAbbreviationselement(Element abbreviaitons_element) { + abbreviationsList.clear(); + + NodeList abbreviation_nodes = abbreviaitons_element.getElementsByTagName("abbreviation"); + for (int i = 0; i < abbreviation_nodes.getLength(); i ++) + { + Element abbr = (Element) abbreviation_nodes.item(i); + abbreviationsList.add(new String[] {abbr.getElementsByTagName("abbr-short").item(0).getTextContent(), abbr.getElementsByTagName("abbr-long").item(0).getTextContent()} ); + } + sortAbbreviationList(); } } \ No newline at end of file diff --git a/src/gui/ColorSettingProfile.java b/src/gui/ColorSettingProfile.java index 10b1aa4..86ad511 100644 --- a/src/gui/ColorSettingProfile.java +++ b/src/gui/ColorSettingProfile.java @@ -30,7 +30,7 @@ public ColorSettingProfile(Element profile, String current_profile_name) ColorSettings.currentColorSetting = this; } - public void update(Color text, Color border, Color background) + void update(Color text, Color border, Color background) { this.text = text; this.border = border; diff --git a/src/gui/ColorSettings.java b/src/gui/ColorSettings.java index ca1248f..9a5dd7b 100644 --- a/src/gui/ColorSettings.java +++ b/src/gui/ColorSettings.java @@ -1,13 +1,9 @@ package gui; import java.awt.Color; -import java.awt.Component; -import java.awt.Container; import java.awt.Dimension; import java.awt.GridBagConstraints; import java.awt.GridBagLayout; -import java.util.ArrayList; -import java.util.List; import javax.swing.BoxLayout; import javax.swing.JButton; @@ -16,12 +12,6 @@ import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.JTextField; -import javax.swing.border.MatteBorder; -import javax.swing.border.TitledBorder; - -import edit.CellEditDialog; -import logic.Row; -import logic.Section; public class ColorSettings { @@ -36,7 +26,7 @@ public class ColorSettings static void selectColorSettings(int index) { currentColorSetting = colorSettingProfiles[index]; - applyLightingMode(); + MainGui.updateLightingSettings(); } private static void fillColorSettingsPane(JPanel options_panel, ColorSettingProfile color_setting) @@ -103,7 +93,7 @@ private static void fillColorSettingsRow(JPanel panel, GridBagConstraints gbc, C private static void updateCustomColorSettings(JDialog options) { int[][] colors = new int[3][3]; - getAllComponents(options).stream().filter(comp -> comp instanceof JTextField).forEach(text -> { + GuiHelper.getAllComponents(options).stream().filter(comp -> comp instanceof JTextField).forEach(text -> { String name = text.getName(); colors[name.startsWith("Text") ? 0 : name.startsWith("Border") ? 1 : 2][name.endsWith("r") ? 0 : name.endsWith("g") ? 1 : 2] = getColorInt( (JTextField) text); }); @@ -129,49 +119,6 @@ private static int getColorInt(JTextField text) return res; } - - static void applyLightingMode() - { - // backgrounds - MainGui.window.setBackground(ColorSettings.getBackgroundColor() ); - MainGui.scrollPane.setBackground(ColorSettings.getBackgroundColor() ); - MainGui.mainPanel.setBackground(ColorSettings.getBackgroundColor() ); - - // text for cells - for (JLabel label : MainGui.labelsText) label.setForeground(ColorSettings.getTextColor() ); - - // text for add-remove-controls - for (JLabel label : MainGui.labelsTextsHideWhenNotInEdit) label.setForeground(MainGui.inEditMode ? ColorSettings.getTextColor() : ColorSettings.getBackgroundColor() ); - - // border color for sections - for (Section section : MainGui.sectionsList) - if (section.getBorder() != null) - ((TitledBorder) section.getBorder() ).setTitleColor(ColorSettings.getTextColor() ); - - // border for cells - for (Section section : MainGui.sectionsList) - for (Row row : section.getRows() ) - for (JPanel cell : row.getCells() ) - if (cell.getBorder() != null) - cell.setBorder(new MatteBorder( ((MatteBorder) cell.getBorder() ).getBorderInsets(), ColorSettings.getBorderColor() ) ); - - // border for section label cells - for (JLabel label : MainGui.sectionLabels) - { - label.setBorder(new MatteBorder( ((MatteBorder) label.getBorder() ).getBorderInsets(), ColorSettings.getBorderColor() ) ); - label.setForeground(ColorSettings.getTextColor() ); - } - - // background and border for sectionManagerDialog - if (edit.SectionManagerDialog.sectionManagerPanel!= null) - { - edit.SectionManagerDialog.sectionManagerPanel.setBackground(ColorSettings.getBackgroundColor() ); - edit.SectionManagerDialog.sectionManagerPanel.setBorder(new MatteBorder( ((MatteBorder) edit.SectionManagerDialog.sectionManagerPanel.getBorder() ).getBorderInsets(), ColorSettings.getTextColor() ) ); - } - - // unpdate CellEditDialog - CellEditDialog.updateColorSettings(); - } static void changeCustomLightingSettings() { @@ -221,16 +168,4 @@ static void changeCustomLightingSettings() options.setVisible(true); options.repaint(); } - - private static List getAllComponents(final Container c) - { - List compList = new ArrayList(); - for (Component comp : c.getComponents()) { - compList.add(comp); - if (comp instanceof Container) - compList.addAll(getAllComponents((Container) comp)); - } - return compList; - } - } diff --git a/src/gui/GuiHelper.java b/src/gui/GuiHelper.java index ad41619..995b7f6 100644 --- a/src/gui/GuiHelper.java +++ b/src/gui/GuiHelper.java @@ -10,6 +10,8 @@ import java.awt.image.BufferedImage; import java.io.File; import java.io.IOException; +import java.util.ArrayList; +import java.util.List; import javax.imageio.ImageIO; import javax.swing.BorderFactory; @@ -46,7 +48,13 @@ public class GuiHelper */ public static TitledBorder getTitledBorderWithCorrectTextColor(String title) { - TitledBorder border = BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(EtchedBorder.RAISED), title); + TitledBorder border = BorderFactory.createTitledBorder( + BorderFactory.createEtchedBorder( + EtchedBorder.RAISED//, + //ColorSettings.getTextColor(), + //ColorSettings.getBorderColor() + ), + title); border.setTitleFont(MainGui.titleFont); border.setTitleColor(ColorSettings.getTextColor()); return border; @@ -60,7 +68,7 @@ public static TitledBorder getTitledBorderWithCorrectTextColor(String title) */ public static MatteBorder getSpacingBorder(int width) { - return BorderFactory.createMatteBorder(width, width, width, width, ColorSettings.getBackgroundColor()); + return BorderFactory.createMatteBorder(width, width, width, width, ColorSettings.getBackgroundColor() ); } /** @@ -402,4 +410,15 @@ private static ImageIcon getScaledLinebreakImageIcon() throw new RuntimeException("Error while loading 'Linebreak.png', file doesn't exist!"); } } + + public static List getAllComponents(final Container c) + { + List compList = new ArrayList(); + for (Component comp : c.getComponents()) { + compList.add(comp); + if (comp instanceof Container) + compList.addAll(getAllComponents((Container) comp)); + } + return compList; + } } diff --git a/src/gui/MainGui.java b/src/gui/MainGui.java index 4831e9b..b531b92 100644 --- a/src/gui/MainGui.java +++ b/src/gui/MainGui.java @@ -9,15 +9,12 @@ import java.io.FileNotFoundException; import java.io.PrintStream; import java.util.ArrayList; -import java.util.HashSet; -import java.util.Set; import java.util.regex.Pattern; import javax.swing.BoxLayout; import javax.swing.JCheckBoxMenuItem; import javax.swing.JDialog; import javax.swing.JFrame; -import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.JScrollPane; import javax.swing.ScrollPaneConstants; @@ -38,6 +35,9 @@ public class MainGui { public static Font font = new Font("Serif", Font.PLAIN, 20); static Font titleFont = new Font("Serif", Font.PLAIN, 15); + private static SectionManagerDialog sectionManagerDialog; + public static CellEditDialog cellEditDialog; + public static JFrame window; public static JScrollPane scrollPane; public static JPanel mainPanel; @@ -47,16 +47,12 @@ public class MainGui { public static boolean contentRearraged = false; private static int height = 0; private static int scrollValue = 0; - public static Set sectionLabels = new HashSet(); - public static Set labelsText = new HashSet(); - public static Set labelsTextsHideWhenNotInEdit = new HashSet(); - public static Set labelsIconsHideWhenNotInEdit = new HashSet(); public static ArrayList
sectionsList = new ArrayList
(); public static Dimension screensize; - public static String currentVersionTag = "v3.0"; + public static String currentVersionTag = "v3.1"; private static void prepareGui() { @@ -79,9 +75,6 @@ private static void prepareGui() window.setTitle(""); window.pack(); window.setVisible(true); - - SectionManagerDialog.initializeSectionDialog(); - CellEditDialog.initializeCellEditDialog(); } public static void arrangeContent() @@ -94,10 +87,11 @@ public static void arrangeContent() scrollValue = scrollPane.getVerticalScrollBar().getValue(); contentRearraged = true; - if (inEditMode) SectionManagerDialog.updateSectionManagerDialog(); + if (inEditMode) sectionManagerDialog.updateSectionManagerDialog(); window.remove(scrollPane); window.setPreferredSize(null); + window.setTitle(FileOperations.getWindowTitle() ); mainPanel = new JPanel(); mainPanel.setLayout(new BoxLayout(mainPanel, BoxLayout.Y_AXIS) ); @@ -198,10 +192,10 @@ public void run() try { FileOperations.setDefaulSettings(); prepareGui(); - FileOperations.readOldSettingsFile(); - //FileOperations.readSettingsFile(); - readAndDisplayOldNotes(); - //readAndDisplayNotes(); + FileOperations.readSettingsFile(); + sectionManagerDialog = new SectionManagerDialog(); + cellEditDialog = new CellEditDialog(); + readAndDisplayNotes(); } catch (Exception e) { try { @@ -249,13 +243,28 @@ public void windowClosing(WindowEvent e) GuiHelper.resizeAndCenterRelativeToMainWindow(dialog); dialog.setVisible(true); } - - static void readAndDisplayOldNotes() + + public static void addSection(int section_index, Section new_section) { - FileOperations.readOldNotesFile(); + sectionsList.add(section_index, new Section("new section") ); arrangeContent(); spaceColums(); - FileOperations.unsavedChanges = false; + sectionManagerDialog.updateSectionManagerDialog(); + } + + public static void removeSection(int section_index) + { + arrangeContent(); + spaceColums(); + sectionManagerDialog.updateSectionManagerDialog(); + } + + public static void renameSection(int section_index, String new_title) + { + sectionsList.get(section_index).setTitle(new_title); + arrangeContent(); + spaceColums(); + sectionManagerDialog.updateSectionManagerDialog(); } static void readAndDisplayNotes() @@ -274,32 +283,43 @@ public static void exit() while(!LiveSplitConnection.readyToExit() ); System.exit(0); } + + public static void updateLightingSettings() + { + window.setBackground(ColorSettings.getBackgroundColor() ); + scrollPane.setBackground(ColorSettings.getBackgroundColor() ); + mainPanel.setBackground(ColorSettings.getBackgroundColor() ); + + sectionManagerDialog.updateLightingMode(); + + cellEditDialog.updateLightingSettings(); + + for (Section section : sectionsList) + section.updateLightingSettings(); + } static void updateEditMode(JCheckBoxMenuItem check_box) { - MainGui.inEditMode = check_box.isSelected(); - if (MainGui.inEditMode) + inEditMode = check_box.isSelected(); + for (Section section : sectionsList) + section.updateEditMode(); + + sectionManagerDialog.updateEditMode(); + + if (inEditMode) { - for (JLabel label : MainGui.labelsTextsHideWhenNotInEdit) label.setForeground(ColorSettings.getTextColor() ); - SectionManagerDialog.updateSectionManagerDialog(); } else { - for (JLabel label : MainGui.labelsTextsHideWhenNotInEdit) label.setForeground(ColorSettings.getBackgroundColor() ); - SectionManagerDialog.sectionManagerDialog.setVisible(false); - CellEditDialog.hideEditDialog(); + cellEditDialog.hideEditDialog(); } - for (JLabel label : MainGui.labelsIconsHideWhenNotInEdit) label.setVisible(MainGui.inEditMode); - MainGui.spaceColums(); + + spaceColums(); } public static void reset() { sectionsList.clear(); - sectionLabels.clear(); - labelsText.clear(); - labelsTextsHideWhenNotInEdit.clear(); - labelsIconsHideWhenNotInEdit.clear(); mainPanel.removeAll(); } diff --git a/src/gui/MenuItems.java b/src/gui/MenuItems.java index 0d6d851..eb91313 100644 --- a/src/gui/MenuItems.java +++ b/src/gui/MenuItems.java @@ -43,7 +43,6 @@ static JMenuBar createMenuBar() // Menu Items // File JMenuItem file_open = new JMenuItem("Open"); - JMenuItem file_open_old = new JMenuItem("Open old"); JMenuItem file_reload = new JMenuItem("Reload"); JMenuItem file_new = new JMenuItem("New notes"); JMenuItem file_save = new JMenuItem("Save"); @@ -75,7 +74,6 @@ static JMenuBar createMenuBar() // Action Listeners // File file_open .addActionListener( e -> { FileOperations.selectNotesFile(); MainGui.readAndDisplayNotes();} ); - file_open_old.addActionListener( e -> { FileOperations.selectNotesFile(); MainGui.readAndDisplayOldNotes();} ); file_reload .addActionListener( e -> { MainGui.keepGuiSize = false; edit_enabled.setSelected(false); MainGui.inEditMode = false; MainGui.readAndDisplayNotes(); } ); file_new .addActionListener( e -> { FileOperations.createNewFile(); } ); file_save .addActionListener( e -> { FileOperations.saveFile(); } ); @@ -117,7 +115,6 @@ static JMenuBar createMenuBar() // Filling Menus // Fill File Menu menu_file.add(file_open); - menu_file.add(file_open_old); menu_file.add(file_reload); menu_file.add(file_new); menu_file.add(file_save); diff --git a/src/logic/AddRemoveControl.java b/src/logic/AddRemoveControl.java index 3f722a0..45f40f5 100644 --- a/src/logic/AddRemoveControl.java +++ b/src/logic/AddRemoveControl.java @@ -15,6 +15,7 @@ public class AddRemoveControl extends JPanel private static final long serialVersionUID = -110941854879740768L; private Row row; private int sectionIndex; + private JLabel add, remove; private AddRemoveControl(Row row, int section_index, boolean only_add) { @@ -23,21 +24,19 @@ private AddRemoveControl(Row row, int section_index, boolean only_add) this.row = row; this.sectionIndex = section_index; - JLabel add = GuiHelper.getAlignedNonOpaqueJLabelWithCurrentColors(" + ", GuiHelper.CENTER); - add.setForeground(ColorSettings.getBackgroundColor() ); + add = GuiHelper.getAlignedNonOpaqueJLabelWithCurrentColors(" + ", GuiHelper.CENTER); + add.setForeground(MainGui.inEditMode ? ColorSettings.getTextColor() : ColorSettings.getBackgroundColor() ); add.addMouseListener(row == null ? MouseAdapters.addSectionAdapter : MouseAdapters.addRowAdapter); - MainGui.labelsTextsHideWhenNotInEdit.add(add); this.add(new JLabel()); this.add(add); if (! only_add) { - JLabel remove = GuiHelper.getAlignedNonOpaqueJLabelWithCurrentColors(" - ", GuiHelper.CENTER); - remove.setForeground(ColorSettings.getBackgroundColor() ); + remove = GuiHelper.getAlignedNonOpaqueJLabelWithCurrentColors(" - ", GuiHelper.CENTER); + remove.setForeground(MainGui.inEditMode ? ColorSettings.getTextColor() : ColorSettings.getBackgroundColor() ); remove.addMouseListener(row == null ? MouseAdapters.removeSectionAdapter : MouseAdapters.removeRowAdapter); - MainGui.labelsTextsHideWhenNotInEdit.add(remove); this.add(remove); this.add(new JLabel()); } @@ -65,6 +64,18 @@ public static AddRemoveControl createAddSectionControl(int section_index) return new AddRemoveControl(null, section_index, true); } + public void updateLightingMode() + { + add.setForeground(MainGui.inEditMode ? ColorSettings.getTextColor() : ColorSettings.getBackgroundColor() ); + if (remove != null) + remove.setForeground(MainGui.inEditMode ? ColorSettings.getTextColor() : ColorSettings.getBackgroundColor() ); + } + + public void updateEditMode() + { + this.updateLightingMode(); + } + public Row getRow() { return row; } public int getSectionIndex() { return sectionIndex; } } \ No newline at end of file diff --git a/src/logic/Cell.java b/src/logic/Cell.java index 4aa9b35..bbd6389 100644 --- a/src/logic/Cell.java +++ b/src/logic/Cell.java @@ -9,6 +9,7 @@ import javax.swing.Icon; import javax.swing.JLabel; import javax.swing.JPanel; +import javax.swing.border.MatteBorder; import org.w3c.dom.Document; import org.w3c.dom.Element; @@ -34,7 +35,7 @@ public class Cell extends JPanel private String[][] actionsArray = new String[0][0]; private ArrayList cellLabels; - Cell(Row row, String cell_str, int col) + Cell(Row row, int col, String cell_str) { this.row = row; this.col = col; @@ -192,6 +193,15 @@ public Cell[] getNeighbours() return res; } + public void updateLightingSettings() + { + + this.setBorder(new MatteBorder( ((MatteBorder) this.getBorder() ).getBorderInsets(), ColorSettings.getBorderColor() ) ); + + for (CellLabel label : cellLabels) + label.updateLightingSettings(); + } + Element getXMLElement(Document doc) { Element result = doc.createElement("cell"); @@ -210,7 +220,7 @@ Element getXMLElement(Document doc) Element actionElement = doc.createElement("action"); actionElement.setAttribute("command", action[0] ); - actionElement.setAttribute("parameter", action[1] ); + actionElement.setAttribute("parameter", actionParameterContainsSensitiveInformation(action[1] ) ? "" : action[1] ); result.appendChild(actionElement); } @@ -219,6 +229,15 @@ Element getXMLElement(Document doc) return result; } + private boolean actionParameterContainsSensitiveInformation(String actionCommand) + { + switch (actionCommand) + { + case "file_to_clipboard": return true; + default: return false; + } + } + public abstract class CellLabel extends JLabel { // auto-generated serialVersionUID @@ -241,6 +260,7 @@ private CellLabel(int index) public int getIndex() { return index; } public abstract void reloadImage(); + public abstract void updateLightingSettings(); } private class TextLabel extends CellLabel @@ -253,7 +273,6 @@ public TextLabel(String str, int index) super(str, index); this.setFont(MainGui.font); this.setForeground(ColorSettings.getTextColor() ); - MainGui.labelsText.add(this); } public EditPanel getEditPanel() @@ -261,6 +280,11 @@ public EditPanel getEditPanel() return new EditTextField(this.getText() ); } + public void updateLightingSettings() + { + this.setForeground(ColorSettings.getTextColor() ); + } + public void reloadImage() {} } @@ -325,6 +349,11 @@ public EditPanel getEditPanel() return new EditIconLabel(icon, mainImageAbbr, layeredImageAbbr, verticalAlignment, horizontalAlignment); } + public void updateLightingSettings() + { + this.setForeground(ColorSettings.getTextColor() ); + } + public Icon getIcon() { return icon; } } } diff --git a/src/logic/FileOperations.java b/src/logic/FileOperations.java index d25d6fa..a91e57b 100644 --- a/src/logic/FileOperations.java +++ b/src/logic/FileOperations.java @@ -40,8 +40,8 @@ public class FileOperations { - public static String fileNotesDirectory = ""; - public static String fileNotesName = ""; + private static String fileNotesDirectory = ""; + private static String fileNotesName = ""; public static String fileAbbreviations = ""; public static String imagesDirectory = ""; @@ -61,9 +61,12 @@ public static void selectNotesFile() fileNotesDirectory = dialog.getDirectory(); fileNotesName = dialog.getFile(); - String new_title = fileNotesName.replace('_', ' '); MainGui.keepGuiSize = false; - MainGui.window.setTitle(new_title); + } + + public static String getWindowTitle() + { + return fileNotesName.replace("_", " "); } public static Stream getStreamOfNamesOfImagesInImagesDirectory() @@ -148,95 +151,6 @@ public static void readSettingsFile() } } - public static void readOldSettingsFile() - { - setDefaulSettings(); - - File settings = new File("settings.txt"); - new File("Images\\").mkdir(); // creates Images directory if it does not exist - - try { - // no settings file - if ( !settings.createNewFile() ) - { - BufferedReader reader; - try { - reader = new BufferedReader(new FileReader(settings) ); - } catch (FileNotFoundException e) { - throw new RuntimeException("Settings File not found!"); - } - - String line; - int[][] colors = new int[3][3]; - - // last used notes-file - if (null != (line = reader.readLine() ) ) // last notes-file - { - int split = line.lastIndexOf('\\'); - fileNotesDirectory = line.substring(0, split + 1); - fileNotesName = line.substring(split + 1); - } - - // color settings - ArrayList colors_list = new ArrayList(); - while ( (line = reader.readLine() ) != null) - { - String color_setting_name = line; - if ( !line.equals("Light") && !line.equals("Dark") && !line.equals("Custom") ) // All color settings are read - break; - - for (int i = 0; i < 3 && (line = reader.readLine() ) != null; i ++) - { - colors[i] = Stream.of(line.split(":") ).mapToInt(Integer::parseInt).toArray(); - - if (i == 2) - colors_list.add(new ColorSettingProfile(color_setting_name, new Color(colors[0][0], colors[0][1], colors[0][2] ), - new Color(colors[1][0], colors[1][1], colors[1][2] ), - new Color(colors[2][0], colors[2][1], colors[2][2] ) - ) ); - } - } - if (colors_list.size() > 0) - ColorSettings.colorSettingProfiles = colors_list.toArray(new ColorSettingProfile[colors_list.size() ] ); - - // hotkey settings - String workaraound_activated = line; - if (workaraound_activated != null && !workaraound_activated.isEmpty() ) - SpeedRunMode.workaround_box.setSelected(Boolean.parseBoolean(workaraound_activated.split(":")[1] ) ); - - String activeProfile = line = reader.readLine(); - - if (activeProfile != null) - { - Hotkeys.profiles.clear(); - - // reading - while (null != (line = reader.readLine() ) ) - { - HotkeyProfile profile = new HotkeyProfile(line); - - for (int i = 0; i < 4; i ++) - if (null != (line = reader.readLine() ) && !line.isEmpty() ) - Hotkeys.readHotkeySetting(line.split(":"), profile); - - Hotkeys.profiles.add(profile); - } - - // setting active profile - for (HotkeyProfile profile : Hotkeys.profiles) - if (profile.name.equals(activeProfile) ) - { - Hotkeys.activeProfile = profile; - break; - } - } - reader.close(); - } - } catch (IOException e) { - e.printStackTrace(); - } - } - public static void readNotesFile() { PopupAlerts.createMissingImagesMessage = true; @@ -278,81 +192,18 @@ public static void readNotesFile() private static void parseNotesElement(Element notes) { - imagesDirectory = notes.getElementsByTagName("images-directory").item(0).getTextContent(); - fileAbbreviations = notes.getElementsByTagName("abbreviations-file").item(0).getTextContent(); - - Abbreviations.setAbbreviationsList(readAbbriviationsFile() ); - - for (int sectoins_index = 0; sectoins_index < notes.getElementsByTagName("section").getLength(); sectoins_index ++ ) - MainGui.sectionsList.add(new Section( (Element) notes.getElementsByTagName("section").item(sectoins_index) ) ); - } - - public static void readOldNotesFile() - { - PopupAlerts.createMissingImagesMessage = true; - MainGui.reset(); - numberOfColumns = 0; - - BufferedReader reader = null; - while (reader == null) + NodeList image_list = notes.getElementsByTagName("images-directory"); + NodeList abbrs_list = notes.getElementsByTagName("abbreviations-file"); + if (image_list.getLength() > 0) + imagesDirectory = image_list.item(0).getTextContent(); + if (abbrs_list.getLength() > 0) { - try { - reader = new BufferedReader(new FileReader(fileNotesDirectory + fileNotesName) ); - } catch (FileNotFoundException e) { - selectNotesFile(); - } + fileAbbreviations = abbrs_list.item(0).getTextContent(); + Abbreviations.setAbbreviationsList(readAbbriviationsFile() ); } - String line_string; - try { - line_string = reader.readLine(); - - // Checking for abbreviations file - if (line_string.startsWith("***image_directory;") ) - { - imagesDirectory = line_string.split(";")[1]; - line_string = reader.readLine(); - } - } catch (Exception e) { - throw new RuntimeException("Error while reading header!"); - } - - try { - // Checking for abbreviations file - if (line_string.startsWith("***abbreviations_file;") ) - { - fileAbbreviations = line_string.split(";")[1]; - Abbreviations.setAbbreviationsList(readAbbriviationsFile() ); - line_string = reader.readLine(); - } - } catch (Exception e) { - throw new RuntimeException("Error while reading header!"); - } - - String title_pattern = "---.*---.*"; - Section current_section; - try - { - while (line_string != null) - { - current_section = new Section(line_string); - MainGui.sectionsList.add(current_section); - - line_string = reader.readLine(); - - while (line_string != null && !line_string.matches(title_pattern)) - { - current_section.addRow(line_string); - line_string = reader.readLine(); - } - - current_section.addEmptyRow(); - current_section.fillPanel(); - } - } catch (IOException e) - { - e.printStackTrace(); - } + for (int sections_index = 0; sections_index < notes.getElementsByTagName("section").getLength(); sections_index ++ ) + MainGui.sectionsList.add(new Section( (Element) notes.getElementsByTagName("section").item(sections_index) ) ); } public static void writeSettingsFile() @@ -423,11 +274,10 @@ public static void createNewFile() { fileNotesDirectory = fileNotesName = null; MainGui.reset(); + numberOfColumns = 2; Section section = new Section("section 1"); - section.addRow("new;file"); MainGui.sectionsList.add(section); - numberOfColumns = 2; MainGui.arrangeContent(); MainGui.contentRearraged = false; // to reset the height of the window @@ -574,20 +424,23 @@ public static void saveAsFile() saveFile(); } - private static Element getNotesElement(Document doc) + private static Element getNotesElement(Document doc, boolean include_flie_locations) { // root element Element notesElement = doc.createElement("notes"); - // image directory - Element imagesElement = doc.createElement("images-directory"); - imagesElement.setTextContent(imagesDirectory); - notesElement.appendChild(imagesElement); - - // abbr file - Element abbreviationsElement = doc.createElement("abbreviations-file"); - abbreviationsElement.setTextContent(fileAbbreviations); - notesElement.appendChild(abbreviationsElement); + if (include_flie_locations) + { + // image directory + Element imagesElement = doc.createElement("images-directory"); + imagesElement.setTextContent(imagesDirectory); + notesElement.appendChild(imagesElement); + + // abbr file + Element abbreviationsElement = doc.createElement("abbreviations-file"); + abbreviationsElement.setTextContent(fileAbbreviations); + notesElement.appendChild(abbreviationsElement); + } // section for (Section section : MainGui.sectionsList) @@ -612,7 +465,7 @@ public static void saveFile() // root elements Document doc = docBuilder.newDocument(); - doc.appendChild(getNotesElement(doc) ); + doc.appendChild(getNotesElement(doc, true) ); // write dom document to a file Transformer transformer = TransformerFactory.newInstance().newTransformer(); @@ -669,13 +522,13 @@ public static void importFile() // selecting where to save the notes file fileNotesName = fileNotesName.replace("_export", ""); int split = fileNotesName.lastIndexOf('.'); - fileNotesName = fileNotesName.substring(0, split + 1) + "_import.xml"; - fileAbbreviations = fileNotesDirectory + fileNotesName.substring(0, split + 1) + "_abbr.txt"; + fileNotesName = fileNotesName.substring(0, split) + "_import.xml"; + fileAbbreviations = fileNotesDirectory + fileNotesName.substring(0, split) + "_abbr.txt"; Element export_element = (Element) doc.getChildNodes().item(0); - parseNotesElement( (Element) export_element.getElementsByTagName("notes").item(0) ); Abbreviations.parseAbbreviationselement( (Element) export_element.getElementsByTagName("abbreviations").item(0) ); + parseNotesElement( (Element) export_element.getElementsByTagName("notes").item(0) ); } catch (SAXParseException e) { @@ -697,7 +550,7 @@ public static void importFile() MainGui.arrangeContent(); MainGui.spaceColums(); - FileOperations.unsavedChanges = false; + FileOperations.unsavedChanges = true; } public static void exportFile() @@ -705,7 +558,7 @@ public static void exportFile() String[] file_name_split = fileNotesName.split(Pattern.quote(".") ); FileDialog dialog = new FileDialog(MainGui.window, "Select export loaction", FileDialog.SAVE); dialog.setDirectory(fileNotesDirectory); - dialog.setFile(file_name_split[0] + "_export." + file_name_split[1]); + dialog.setFile(file_name_split[0] + "_export.xml"); GuiHelper.resizeAndCenterRelativeToMainWindow(dialog); dialog.setVisible(true); @@ -723,7 +576,7 @@ public static void exportFile() Element export_element = doc.createElement("export"); doc.appendChild(export_element); - export_element.appendChild(getNotesElement(doc) ); + export_element.appendChild(getNotesElement(doc, false) ); export_element.appendChild(Abbreviations.getAbbreviationsElement(doc) ); // write dom document to a file diff --git a/src/logic/Hotkeys.java b/src/logic/Hotkeys.java index 6d4df9c..31efe48 100644 --- a/src/logic/Hotkeys.java +++ b/src/logic/Hotkeys.java @@ -118,43 +118,6 @@ static void selectLiveSplitFile(ArrayList new_profiles) importHotkeySettings(dir, new_profiles); } - static void readHotkeySetting(String[] setting, HotkeyProfile profile) - { - String[] keys = setting[1].split(","); - if (keys == null || keys.length == 0 || keys[0].equals("0") ) // undefined hotkey - return; - switch (setting[0] ) - { - case "Split": - profile.eventSplitKey = Integer.valueOf(keys[0] ); - profile.eventSplitLocation = Integer.valueOf(keys[1] ); - for (int i = 2; i < keys.length; i ++) - profile.eventSplitModifier += Integer.valueOf(keys[i] ); - break; - - case "Reset": - profile.eventResetKey = Integer.valueOf(keys[0] ); - profile.eventResetLocation = Integer.valueOf(keys[1] ); - for (int i = 2; i < keys.length; i ++) - profile.eventResetModifier += Integer.valueOf(keys[i] ); - break; - - case "Skip": - profile.eventSkipKey = Integer.valueOf(keys[0] ); - profile.eventSkipLocation = Integer.valueOf(keys[1] ); - for (int i = 2; i < keys.length; i ++) - profile.eventSkipModifier += Integer.valueOf(keys[i] ); - break; - - case "Undo": - profile.eventUndoKey = Integer.valueOf(keys[0] ); - profile.eventUndoLocation = Integer.valueOf(keys[1] ); - for (int i = 2; i < keys.length; i ++) - profile.eventUndoModifier += Integer.valueOf(keys[i] ); - break; - } - } - private static void importHotkeySettings(String dir_location, ArrayList new_profiles) { try diff --git a/src/logic/MouseAdapters.java b/src/logic/MouseAdapters.java index aec9b6a..dcad182 100644 --- a/src/logic/MouseAdapters.java +++ b/src/logic/MouseAdapters.java @@ -15,11 +15,8 @@ import javax.swing.JLabel; import javax.swing.JOptionPane; -import javax.swing.JPanel; import javax.swing.event.MouseInputAdapter; -import edit.CellEditDialog; -import gui.GuiHelper; import gui.MainGui; import gui.PopupAlerts; @@ -31,12 +28,12 @@ public class MouseAdapters public void mouseClicked(MouseEvent e) { if ( !MainGui.inEditMode) return; - + int buttonPressed = e.getButton(); - + if (buttonPressed == 1 || buttonPressed == 3) { - CellEditDialog.processCell( (Cell) e.getComponent() ); + MainGui.cellEditDialog.processCell( (Cell) e.getComponent() ); if (buttonPressed == 3) PopupMenues.processCellRightClick(e); } @@ -64,10 +61,7 @@ public void mouseClicked(MouseEvent e) { FileOperations.unsavedChanges = true; int section_index = ( (AddRemoveControl) e.getComponent().getParent() ).getSectionIndex(); - MainGui.sectionsList.add(section_index, Section.creatEmptySection() ); - MainGui.arrangeContent(); - MainGui.spaceColums(); - edit.SectionManagerDialog.updateSectionManagerDialog(); + MainGui.addSection(section_index, new Section("new section") ); } } }; @@ -81,10 +75,7 @@ public void mouseClicked(MouseEvent e) { FileOperations.unsavedChanges = true; int section_index = ( (AddRemoveControl) e.getComponent().getParent() ).getSectionIndex(); - MainGui.sectionsList.remove(section_index); - MainGui.arrangeContent(); - MainGui.spaceColums(); - edit.SectionManagerDialog.updateSectionManagerDialog(); + MainGui.removeSection(section_index); } } }; @@ -233,49 +224,9 @@ public void mouseClicked(MouseEvent e) if (newText != null) { label.setText(newText); - MainGui.sectionsList.get(current_section_index).setTitle(newText); - MainGui.arrangeContent(); - MainGui.spaceColums(); - edit.SectionManagerDialog.updateSectionManagerDialog(); - FileOperations.unsavedChanges = true; - } - } - }; - } - - static MouseInputAdapter getEditTodoAdapter(Row row, JPanel panel, JLabel label, JLabel icon) - { - return new MouseInputAdapter() { - @Override - public void mouseClicked(MouseEvent arg0) - { - String string = JOptionPane.showInputDialog(MainGui.window, "TODO", row.getTodoString()); - if (string != null) - { - row.setTodoString(string); + MainGui.renameSection(current_section_index, newText); FileOperations.unsavedChanges = true; - - if (string.isEmpty() && icon != null) // remove existing icon - { - panel.remove(icon); - MainGui.labelsIconsHideWhenNotInEdit.remove(icon); - label.removeMouseListener(this); - label.addMouseListener(getEditTodoAdapter(row, panel, label, null)); - } - - if (!string.isEmpty() && icon == null) // add new icon - { - JLabel new_icon = new JLabel(GuiHelper.scaledTodoImageIcon); - panel.add(new_icon); - new_icon.setVisible(MainGui.inEditMode); - MainGui.labelsIconsHideWhenNotInEdit.add(new_icon); - label.removeMouseListener(this); - label.addMouseListener(getEditTodoAdapter(row, panel, label, new_icon)); - } } - - MainGui.arrangeContent(); - MainGui.spaceColums(); } }; } diff --git a/src/logic/PopupMenues.java b/src/logic/PopupMenues.java index c2c4687..085f212 100644 --- a/src/logic/PopupMenues.java +++ b/src/logic/PopupMenues.java @@ -8,7 +8,7 @@ import javax.swing.JPopupMenu; import javax.swing.SwingUtilities; -import edit.CellEditDialog; +import gui.MainGui; public class PopupMenues { @@ -46,7 +46,7 @@ public void actionPerformed(ActionEvent e) public void actionPerformed(ActionEvent e) { currentCell.updateCell(copiedCellString); - CellEditDialog.processCell(currentCell); + MainGui.cellEditDialog.processCell(currentCell); } }); @@ -78,7 +78,7 @@ public void actionPerformed(ActionEvent e) neighbours[0].updateCell(this_cell_str); currentCell = neighbours[0]; - CellEditDialog.processCell(currentCell); + MainGui.cellEditDialog.processCell(currentCell); } }); @@ -97,7 +97,7 @@ public void actionPerformed(ActionEvent e) neighbours[1].updateCell(this_cell_str); currentCell = neighbours[1]; - CellEditDialog.processCell(currentCell); + MainGui.cellEditDialog.processCell(currentCell); } }); @@ -116,7 +116,7 @@ public void actionPerformed(ActionEvent e) neighbours[2].updateCell(this_cell_str); currentCell = neighbours[2]; - CellEditDialog.processCell(currentCell); + MainGui.cellEditDialog.processCell(currentCell); } }); @@ -135,7 +135,7 @@ public void actionPerformed(ActionEvent e) neighbours[3].updateCell(this_cell_str); currentCell = neighbours[3]; - CellEditDialog.processCell(currentCell); + MainGui.cellEditDialog.processCell(currentCell); } }); diff --git a/src/logic/Row.java b/src/logic/Row.java index 739eae5..1610ea2 100644 --- a/src/logic/Row.java +++ b/src/logic/Row.java @@ -1,11 +1,14 @@ package logic; -import java.util.ArrayList; -import java.util.regex.Pattern; +import java.awt.Component; +import java.awt.event.MouseEvent; +import java.util.ArrayList; -import javax.swing.BoxLayout; import javax.swing.JLabel; +import javax.swing.JOptionPane; import javax.swing.JPanel; +import javax.swing.SwingConstants; +import javax.swing.event.MouseInputAdapter; import org.w3c.dom.Document; import org.w3c.dom.Element; @@ -17,10 +20,9 @@ public class Row { - private JPanel controlPanel; + private AddRemoveControl controlPanel; private ArrayList cells = new ArrayList(); - private String todoString = ""; - private JPanel todoPanel; + private TodoLabel todoLabel; private Section section; private int rowIndex; @@ -31,51 +33,39 @@ public class Row public int getRowIndex() { return rowIndex; } void increaseRowIndex() { rowIndex ++; } void decreaseRowIndex() { rowIndex --; } - public String getTodoString() { return todoString; } - public JPanel getTodoPanel() { return todoPanel; } - public void setTodoString(String todo_string) { todoString = todo_string; } + public String getTodoString() { return todoLabel.todoString; } + public JLabel getTodoPanel() { return todoLabel; } + public void setTodoString(String todo_string) { todoLabel.todoString = todo_string; } - /** - * Creates a empty Row only including the RowControls - * - * @param section The section this row is a part of. - */ - Row(Section section, int row_index) - { - rowIndex = row_index; - this.section = section; - todoPanel = new JPanel(); - todoPanel.setOpaque(false); - todoString = ""; - - controlPanel = AddRemoveControl.createAddRowControl(this); - } + static final boolean EMPTY = false; + static final boolean LAST = true; /** - * Creates a new Row including the RowControls, all Cells and TodoControl + * Creates an empty Row. Depending on last_row, the new row will be empty but full usable or will be the last row of the section which only contains the + button for a new row. + * + * @param section The section this row will be part of. + * @param row_index The index this row will have. + * @param last_row Whether or not the new row is the last row of the section. Possible values are Row.EMPTY and Row.LAST. * - * @param section The section this row is a part of. - * @param row_string The string that defines the row (including todo). - * @param row_index The index of the row within the section. + * @return The new row. */ - Row(Section section, String row_string, int row_index) + Row(Section section, int row_index, boolean last_row) { rowIndex = row_index; this.section = section; - controlPanel = AddRemoveControl.createAddRemoveRowControl(this); - - String[] line_arr = row_string.split(Pattern.quote("||"), 2); - if (line_arr.length == 2) - todoString = line_arr[1]; + if (last_row) + { + todoLabel = new TodoLabel(); + controlPanel = AddRemoveControl.createAddRowControl(this); + } else - todoString = ""; - todoPanel = getTodoControl(); - - String[] cell_strings = line_arr[0].split(";", -1); - for (int col = 0; col < cell_strings.length; col ++) - cells.add(new Cell(this, cell_strings[col], col) ); - if (cell_strings.length > FileOperations.numberOfColumns) FileOperations.numberOfColumns = cell_strings.length; + { + todoLabel = new TodoLabel(""); + controlPanel = AddRemoveControl.createAddRemoveRowControl(this); + for (int i = 0; i < FileOperations.numberOfColumns; i ++) + cells.add(new Cell(this, i, "") ); + } } Row(Section section, int row_index, Element row) @@ -86,9 +76,7 @@ public class Row controlPanel = AddRemoveControl.createAddRemoveRowControl(this); NodeList todo = row.getElementsByTagName("todo"); - if (todo.getLength() == 1) - todoString = todo.item(0).getTextContent(); - todoPanel = getTodoControl(); + todoLabel = new TodoLabel(todo.getLength() == 1 ? todo.item(0).getTextContent() : ""); NodeList cellNodes = row.getElementsByTagName("cell"); if (cellNodes.getLength() > FileOperations.numberOfColumns) @@ -102,30 +90,22 @@ void reloadImages() for (Cell cell : cells) cell.relaodImages(); } - private JPanel getTodoControl() + public void updateLightingSettings() { - JPanel todo_panel = new JPanel(); - todo_panel.setLayout(new BoxLayout(todo_panel, BoxLayout.X_AXIS) ); - todo_panel.setOpaque(false); - JLabel todo_label = new JLabel(" + "); - - todo_label.setForeground(ColorSettings.getTextColor() ); - todo_label.setOpaque(false); - todo_panel.add(todo_label); - - JLabel icon = null; - if (!todoString.equals("") ) - { - icon = new JLabel(GuiHelper.scaledTodoImageIcon); - todo_panel.add(icon); - icon.setVisible(MainGui.inEditMode); - MainGui.labelsIconsHideWhenNotInEdit.add(icon); - } + // todoLabel.updateLightingSettings(); + for (Component comp : controlPanel.getComponents() ) + comp.setForeground(MainGui.inEditMode ? ColorSettings.getTextColor() : ColorSettings.getBackgroundColor() ); - todo_label.addMouseListener(MouseAdapters.getEditTodoAdapter(this, todo_panel, todo_label, icon) ); + for (Cell cell : cells) + cell.updateLightingSettings(); - MainGui.labelsText.add(todo_label); - return todo_panel; + todoLabel.updateLightingSettings(); + } + + public void updateEditMode() + { + controlPanel.updateEditMode(); + todoLabel.updateEditMode(); } Element getXMLElement(Document doc) @@ -135,13 +115,87 @@ Element getXMLElement(Document doc) for (Cell cell : cells) result.appendChild(cell.getXMLElement(doc) ); - if ( !todoString.isEmpty() ) + if ( !todoLabel.todoString.isEmpty() ) { Element todoElement = doc.createElement("todo"); - todoElement.setTextContent(todoString); + todoElement.setTextContent(todoLabel.todoString); result.appendChild(todoElement); } return result; } + + + private final static MouseInputAdapter editTodoAdapter = new MouseInputAdapter() + { + @Override + public void mouseClicked(MouseEvent event) + { + TodoLabel label = (TodoLabel) event.getComponent(); + String string = JOptionPane.showInputDialog(MainGui.window, "TODO", label.getTodoString() ); + if (string != null) + { + label.updateTodoString(string); + FileOperations.unsavedChanges = true; + + label.setIcon(MainGui.inEditMode && !string.isEmpty() ? GuiHelper.scaledTodoImageIcon : null); + } + + MainGui.arrangeContent(); + MainGui.spaceColums(); + } + }; + + private class TodoLabel extends JLabel + { + /** Automatically generated serailVersionUID */ + private static final long serialVersionUID = 1179200440597255671L; + private String todoString; + + public String getTodoString() { return todoString; } + + public TodoLabel(String todo_string) + { + super(" + ", + MainGui.inEditMode && !todo_string.isEmpty() ? GuiHelper.scaledTodoImageIcon : null, + SwingConstants.LEFT); + this.todoString = todo_string; + + this.setOpaque(false); + this.setForeground(ColorSettings.getTextColor() ); + this.addMouseListener(editTodoAdapter); + } + + /** + * Creates an placeholder TodoLabel used on the last row of each section (now content, just the add row control). + */ + public TodoLabel() + { + super(); + this.todoString = ""; + this.setOpaque(false); + } + + public void updateTodoString(String new_todo_string) + { + this.todoString = new_todo_string; + this.updateIcon(); + } + + private void updateLightingSettings() + { + this.setForeground(ColorSettings.getTextColor() ); + } + + private void updateEditMode() + { + this.updateIcon(); + } + + private void updateIcon() + { + this.setIcon(MainGui.inEditMode && !todoString.isEmpty() ? GuiHelper.scaledTodoImageIcon : null); + this.setHorizontalTextPosition(SwingConstants.LEADING); + } + } } diff --git a/src/logic/Section.java b/src/logic/Section.java index 0ebc04e..63c955d 100644 --- a/src/logic/Section.java +++ b/src/logic/Section.java @@ -7,10 +7,13 @@ import java.util.ArrayList; import javax.swing.JPanel; +import javax.swing.border.TitledBorder; import org.w3c.dom.Document; import org.w3c.dom.Element; +import org.w3c.dom.NodeList; +import gui.ColorSettings; import gui.GuiHelper; public class Section extends JPanel @@ -32,17 +35,26 @@ public class Section extends JPanel public int getScrollLocation() { return scrollLocation; } public ArrayList getRows() { return rows; } - Section(String header) + /** + * Creates an empty section containing an empty row. + * + * @param header + */ + public Section(String header) { // title - title = header.split(";")[0].replace("---", ""); + title = header; this.setBorder(GuiHelper.getTitledBorderWithCorrectTextColor(title) ); + this.addEmptyRow(); + this.addLastRow(); + this.setLayout(new GridBagLayout() ); gbc = new GridBagConstraints(); gbc.fill = GridBagConstraints.BOTH; this.setAlignmentY(Component.LEFT_ALIGNMENT); this.setOpaque(false); + this.fillPanel(); } Section(Element section) @@ -50,8 +62,9 @@ public class Section extends JPanel title = section.getElementsByTagName("title").item(0).getTextContent(); this.setBorder(GuiHelper.getTitledBorderWithCorrectTextColor(title) ); - for (int row_index = 0; row_index < section.getElementsByTagName("row").getLength(); row_index ++ ) - rows.add(new Row(this, rows.size(), (Element) section.getElementsByTagName("row").item(row_index) ) ); + NodeList rowElementsList = section.getElementsByTagName("row"); + for (int row_index = 0; row_index < rowElementsList.getLength(); row_index ++ ) + rows.add(new Row(this, row_index, (Element) rowElementsList.item(row_index) ) ); this.setLayout(new GridBagLayout() ); gbc = new GridBagConstraints(); @@ -59,26 +72,18 @@ public class Section extends JPanel this.setAlignmentY(Component.LEFT_ALIGNMENT); this.setOpaque(false); - this.addEmptyRow(); + this.addLastRow(); this.fillPanel(); } - static Section creatEmptySection() + private void addEmptyRow() { - Section section = new Section("title"); - section.addEmptyRow(); - section.fillPanel(); - return section; + rows.add(new Row(this, rows.size(), Row.EMPTY) ); } - void addEmptyRow() + private void addLastRow() { - rows.add(new Row(this, rows.size() ) ); - } - - void addRow(String row_string) - { - rows.add(new Row(this, row_string, rows.size() ) ); + rows.add(new Row(this, rows.size(), Row.LAST) ); } public void reloadImages() @@ -86,7 +91,7 @@ public void reloadImages() for (Row row : rows) row.reloadImages(); } - void fillPanel() + private void fillPanel() { this.removeAll(); @@ -160,10 +165,7 @@ public void setLocation() void addContentLine(int row_to_add) { - String new_row_string = ""; - for (int i = 0; i < FileOperations.numberOfColumns - 1; i ++) - new_row_string += ";"; - rows.add(row_to_add, new Row(this, new_row_string, row_to_add) ); + rows.add(row_to_add, new Row(this, row_to_add, Row.EMPTY) ); fillPanel(); } @@ -191,7 +193,7 @@ void addContentColumn(int new_column) if (cell.getCol() >= new_column) cell.increaseCol(); if (row.getRowIndex() != rows.size() - 1 ) - row.getCells().add(new_column, new Cell(row, " ", new_column) ); + row.getCells().add(new_column, new Cell(row, new_column, " ") ); } fillPanel(); } @@ -209,19 +211,18 @@ void removeContentColumn(int old_column) fillPanel(); } - public String getSaveString() + public void updateLightingSettings() { - String res = "---" + title + "---"; + ((TitledBorder) this.getBorder() ).setTitleColor(ColorSettings.getTextColor() ); + for (Row row : rows) - { - res += "\n"; - for (Cell cell : row.getCells() ) - res += cell.getCellString() + ";"; - res = res.substring(0, res.length() - 1); // removing last semicolon (or in case of the empty control row the linebreak resulting in an empty string for all empty control rows) - if (!row.getTodoString().isEmpty() ) - res += "||" + row.getTodoString(); - } - return res; + row.updateLightingSettings(); + } + + public void updateEditMode() + { + for (Row row : rows) + row.updateEditMode(); } Element getXMLElement(Document doc)