-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7 from tangcent/master
Base Code of UITemplateEditor&Builder
- Loading branch information
Showing
12 changed files
with
221 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
icodeless-api/src/main/java/com/itangcent/icode/api/EditableTemplateManager.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package com.itangcent.icode.api; | ||
|
||
|
||
public interface EditableTemplateManager extends TemplateManager { | ||
|
||
/** | ||
* Find template by name. | ||
* the Template get from EditableTemplateManager should be editable | ||
* | ||
* @param name -template name | ||
* @return the template which is editable | ||
*/ | ||
@Override | ||
EditableTemplate findByName(String name); | ||
|
||
/** | ||
* Find template by name and context. | ||
* The Template get from EditableTemplateManager should be editable | ||
* | ||
* @param name -template name | ||
* @return the template which is editable | ||
*/ | ||
@Override | ||
EditableTemplate findByName(String name, TemplateContext context); | ||
|
||
/** | ||
* Return true if any template was modified. | ||
*/ | ||
boolean isAnyModified(); | ||
|
||
/** | ||
* Save all changes. | ||
*/ | ||
void save(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,9 +2,7 @@ | |
|
||
public interface TemplateEditor { | ||
|
||
void show(); | ||
|
||
void cancel(); | ||
void reset(); | ||
|
||
void save(); | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
115 changes: 115 additions & 0 deletions
115
icodeless-core/src/main/java/com/itangcent/icode/ui/UIContainer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
package com.itangcent.icode.ui; | ||
|
||
import javax.swing.*; | ||
import java.awt.*; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
public interface UIContainer { | ||
|
||
/** | ||
* Appends the specified component to the end of this container. | ||
* <p> | ||
* This method changes layout-related information, and therefore, | ||
* invalidates the component hierarchy. If the container has already been | ||
* displayed, the hierarchy must be validated thereafter in order to | ||
* display the added component. | ||
* | ||
* @param comp the component to be added | ||
* @return the component argument | ||
* @throws NullPointerException if {@code comp} is {@code null} | ||
* @see javax.swing.JComponent#revalidate() | ||
*/ | ||
Component add(Component comp); | ||
|
||
/** | ||
* Removes the <code>Viewport</code>s one lightweight child. | ||
*/ | ||
void remove(Component child); | ||
|
||
/** | ||
* remove all sub components | ||
*/ | ||
void clear(); | ||
|
||
|
||
static UIContainer of(Container container) { | ||
if (container instanceof JScrollPane) { | ||
return new JScrollPaneUIContainer((JScrollPane) container); | ||
} else { | ||
return new BaseUIContainer(container); | ||
} | ||
} | ||
|
||
abstract class AbstractUIContainer implements UIContainer { | ||
|
||
private List<Component> subs = new ArrayList<>(); | ||
|
||
@Override | ||
public Component add(Component comp) { | ||
subs.add(comp); | ||
return doAdd(comp); | ||
} | ||
|
||
@Override | ||
public void remove(Component child) { | ||
subs.remove(child); | ||
doRemove(child); | ||
} | ||
|
||
abstract Component doAdd(Component comp); | ||
|
||
abstract void doRemove(Component child); | ||
|
||
@Override | ||
public void clear() { | ||
if (!subs.isEmpty()) { | ||
for (Component sub : subs) { | ||
doRemove(sub); | ||
} | ||
} | ||
subs.clear(); | ||
} | ||
} | ||
|
||
class BaseUIContainer extends AbstractUIContainer { | ||
|
||
private Container container; | ||
|
||
private BaseUIContainer(Container container) { | ||
this.container = container; | ||
} | ||
|
||
@Override | ||
public Component doAdd(Component comp) { | ||
return container.add(comp); | ||
} | ||
|
||
@Override | ||
public void doRemove(Component child) { | ||
container.remove(child); | ||
} | ||
|
||
} | ||
|
||
class JScrollPaneUIContainer extends AbstractUIContainer { | ||
|
||
|
||
private JScrollPane container; | ||
|
||
private JScrollPaneUIContainer(JScrollPane container) { | ||
this.container = container; | ||
} | ||
|
||
@Override | ||
public Component doAdd(Component comp) { | ||
return container.getViewport().add(comp); | ||
} | ||
|
||
@Override | ||
public void doRemove(Component child) { | ||
container.getViewport().remove(child); | ||
} | ||
} | ||
|
||
} |
15 changes: 15 additions & 0 deletions
15
icodeless-core/src/main/java/com/itangcent/icode/ui/UITemplateEditor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package com.itangcent.icode.ui; | ||
|
||
import com.itangcent.icode.api.AbstractTemplateEditor; | ||
import com.itangcent.icode.api.EditableTemplate; | ||
|
||
import java.awt.*; | ||
|
||
public abstract class UITemplateEditor extends AbstractTemplateEditor { | ||
|
||
public UITemplateEditor(EditableTemplate template) { | ||
super(template); | ||
} | ||
|
||
public abstract Component createUI(); | ||
} |
33 changes: 33 additions & 0 deletions
33
icodeless-core/src/main/java/com/itangcent/icode/ui/UITemplateEditorBuilder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package com.itangcent.icode.ui; | ||
|
||
import com.itangcent.icode.api.EditableTemplate; | ||
import com.itangcent.icode.api.TemplateEditor; | ||
import com.itangcent.icode.api.TemplateEditorBuilder; | ||
|
||
import java.awt.*; | ||
|
||
public abstract class UITemplateEditorBuilder implements TemplateEditorBuilder { | ||
|
||
/** | ||
* The parent container for rendering the template editor | ||
*/ | ||
private UIContainer parentContainer; | ||
|
||
public UITemplateEditorBuilder(Container parentContainer) { | ||
this.parentContainer = UIContainer.of(parentContainer); | ||
} | ||
|
||
@Override | ||
public TemplateEditor createEditor(EditableTemplate template) { | ||
UITemplateEditor uiTemplateEditor = buildEditor(template); | ||
addEditorUIToParent(uiTemplateEditor.createUI()); | ||
return uiTemplateEditor; | ||
} | ||
|
||
protected void addEditorUIToParent(Component editorUI) { | ||
parentContainer.clear(); | ||
parentContainer.add(editorUI); | ||
} | ||
|
||
protected abstract UITemplateEditor buildEditor(EditableTemplate template); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 0 additions & 11 deletions
11
...dea/src/main/java/com/itangcent/idea/plugin/template/manager/EditableTemplateManager.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters