001: /*
002: * BorderExample.java
003: *
004: * Created on 31. Mai 2007, 14:37
005: *
006: * To change this template, choose Tools | Template Manager
007: * and open the template in the editor.
008: */
009:
010: package org.wings.example;
011:
012: import java.awt.Color;
013: import javax.swing.ImageIcon;
014: import org.wings.*;
015: import org.wings.plaf.WingSetExample;
016: import org.wings.border.*;
017:
018: /**
019: * BorderDemo.java requires the following file:
020: * images/wavy.gif
021: * @author pet
022: */
023: public class BorderExample implements WingSetExample {
024: private SPanel panel;
025:
026: public void activateExample() {
027: SGridLayout layout = new SGridLayout(1, 0);
028: panel = new SPanel(layout);
029:
030: //Keep references to the next few borders,
031: //for use in titles and compound borders.
032: SBorder blackline, raisedetched, loweredetched, raisedbevel, loweredbevel, empty;
033:
034: //A border that puts 10 extra pixels at the sides and
035: //bottom of each pane.
036: SBorder paneEdge = SBorderFactory.createSEmptyBorder(0, 10, 10,
037: 10);
038:
039: blackline = SBorderFactory.createSLineBorder(Color.black);
040: raisedetched = SBorderFactory
041: .createSEtchedBorder(SEtchedBorder.RAISED);
042: loweredetched = SBorderFactory
043: .createSEtchedBorder(SEtchedBorder.LOWERED);
044: raisedbevel = SBorderFactory.createRaisedSBevelBorder();
045: loweredbevel = SBorderFactory.createLoweredSBevelBorder();
046: empty = SBorderFactory.createSEmptyBorder();
047:
048: //First pane: simple borders
049: SPanel simpleBorders = new SPanel();
050: simpleBorders.setBorder(paneEdge);
051: simpleBorders.setLayout(new SBoxLayout(SBoxLayout.Y_AXIS));
052:
053: addCompForBorder(blackline, "line border", simpleBorders);
054: addCompForBorder(raisedetched, "raised etched border",
055: simpleBorders);
056: addCompForBorder(loweredetched, "lowered etched border",
057: simpleBorders);
058: addCompForBorder(raisedbevel, "raised bevel border",
059: simpleBorders);
060: addCompForBorder(loweredbevel, "lowered bevel border",
061: simpleBorders);
062: addCompForBorder(empty, "empty border", simpleBorders);
063:
064: //Second pane: matte borders
065: SPanel matteBorders = new SPanel();
066: matteBorders.setBorder(paneEdge);
067: matteBorders.setLayout(new SBoxLayout(SBoxLayout.Y_AXIS));
068:
069: ImageIcon icon = createImageIcon("images/wavy.gif",
070: "wavy-line border icon"); //20x22
071: //Third pane: titled borders
072: SPanel titledBorders = new SPanel();
073: titledBorders.setBorder(paneEdge);
074: titledBorders.setLayout(new SBoxLayout(SBoxLayout.Y_AXIS));
075: STitledBorder titled;
076:
077: titled = new STitledBorder("title");
078: addCompForBorder(titled, "default titled border"
079: + " (default just., default pos.)", titledBorders);
080:
081: titled = new STitledBorder(blackline, "title");
082: addCompForTitledBorder(titled, "titled line border"
083: + " (centered, default pos.)", STitledBorder.CENTER,
084: STitledBorder.DEFAULT_POSITION, titledBorders);
085:
086: titled = new STitledBorder("title");
087: addCompForTitledBorder(titled, "titled line border Bold"
088: + " (centered, default pos.)", STitledBorder.CENTER,
089: STitledBorder.DEFAULT_POSITION, titledBorders);
090: titled.setTitleFont(new SFont(SFont.BOLD));
091:
092: titled = new STitledBorder("title");
093: addCompForTitledBorder(titled, "titled line border Italix RED"
094: + " (centered, default pos.)", STitledBorder.CENTER,
095: STitledBorder.DEFAULT_POSITION, titledBorders);
096: titled.setTitleFont(new SFont(SFont.ITALIC));
097: titled.setTitleColor(java.awt.Color.RED);
098:
099: titled = new STitledBorder(loweredetched, "title");
100: titled.getBorder().setColor(java.awt.Color.GREEN);
101: addCompForTitledBorder(titled,
102: "titled lowered Green etched border"
103: + " (right just., default pos.)",
104: STitledBorder.RIGHT, STitledBorder.DEFAULT_POSITION,
105: titledBorders);
106:
107: titled = new STitledBorder(loweredbevel, "title");
108: addCompForTitledBorder(titled, "titled lowered bevel border"
109: + " (default just., above top)",
110: STitledBorder.DEFAULT_JUSTIFICATION,
111: STitledBorder.ABOVE_TOP, titledBorders);
112:
113: titled = new STitledBorder(empty, "title");
114: addCompForTitledBorder(titled, "titled empty border"
115: + " (default just., bottom)",
116: STitledBorder.DEFAULT_JUSTIFICATION,
117: STitledBorder.BOTTOM, titledBorders);
118:
119: //Fourth pane: compound borders
120: SPanel compoundBorders = new SPanel();
121: compoundBorders.setBorder(paneEdge);
122: compoundBorders.setLayout(new SBoxLayout(SBoxLayout.Y_AXIS));
123: SBorder redline = SBorderFactory.createSLineBorder(Color.red);
124:
125: STabbedPane tabbedPane = new STabbedPane();
126: tabbedPane.addTab("Simple", null, simpleBorders, null);
127: // tabbedPane.addTab("Matte", null, matteBorders, null);
128: tabbedPane.addTab("Titled", null, titledBorders, null);
129: // tabbedPane.addTab("Compound", null, compoundBorders, null);
130: tabbedPane.setSelectedIndex(0);
131: String toolTip = new String(
132: "<html>Blue Wavy Line border art crew:<br> Bill Pauley<br> Cris St. Aubyn<br> Ben Wronsky<br> Nathan Walrath<br> Tommy Adams, special consultant</html>");
133: tabbedPane.setToolTipTextAt(1, toolTip);
134:
135: panel.add(tabbedPane);
136: }
137:
138: void addCompForTitledBorder(STitledBorder border,
139: String description, int justification, int position,
140: SContainer container) {
141: border.setTitleJustification(justification);
142: //order.setTitlePosition(position);
143: addCompForBorder(border, description, container);
144: }
145:
146: void addCompForBorder(SBorder border, String description,
147: SContainer container) {
148: SPanel comp = new SPanel(new SGridLayout(1, 1));
149: SLabel label = new SLabel(description, SConstants.CENTER);
150: comp.add(label);
151: comp.setBorder(border);
152:
153: // container.add(Box.createRigidArea(new Dimension(0, 10)));
154: container.add(comp);
155: }
156:
157: /** Returns an ImageIcon, or null if the path was invalid. */
158: protected static ImageIcon createImageIcon(String path,
159: String description) {
160: java.net.URL imgURL = BorderExample.class.getResource(path);
161: if (imgURL != null) {
162: return new ImageIcon(imgURL, description);
163: } else {
164: System.err.println("Couldn't find file: " + path);
165: return null;
166: }
167: }
168:
169: public void passivateExample() {
170: //To change body of implemented methods use File | Settings | File Templates.
171: }
172:
173: public SComponent getExample() {
174: return panel;
175: }
176:
177: public String getExampleName() {
178: return "TitledBorder";
179: }
180:
181: public String getExampleGroup() {
182: return "Experiment";
183: }
184: }
|