下面列出了javax.swing.SwingConstants#TOP 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
protected void paintComponent(Graphics graphics) {
graphics.setColor(getBackground());
graphics.fillRect(0, 0, getWidth(), getHeight());
switch (imageAlign) {
case (SwingConstants.TOP):
graphics.drawImage(image, (getWidth() - image.getWidth(null)) / 2, 0, this);
break;
case (SwingConstants.BOTTOM):
graphics.drawImage(image, (getWidth() - image.getWidth(null)) / 2, getHeight() - image.getHeight(null), this);
break;
default:
graphics.drawImage(image, (getWidth() - image.getWidth(null)) / 2, 0, this);
}
}
protected GradientPaint createContentGradient(JComponent c,
boolean isSelected) {
JTabbedPane tabs = getTabbedPaneParent(c);
int placement = tabs == null ? SwingConstants.TOP : tabs
.getTabPlacement();
Color outer = isSelected ? contentOuterSelected
: contentOuterNormal;
Color inner = isSelected ? contentInnerSelected
: contentInnerNormal;
if (placement == SwingConstants.LEFT) {
return (new GradientPaint(0, 0, outer, c.getWidth(), 0, inner));
} else if (placement == SwingConstants.RIGHT) {
return (new GradientPaint(0, 0, inner, c.getWidth(), 0, outer));
} else if (placement == SwingConstants.BOTTOM) {
return (new GradientPaint(0, 0, inner, 0, c.getHeight(), outer));
} else {
return (new GradientPaint(0, 0, outer, 0, c.getHeight(), inner));
}
}
private int layout(ArrayList<Component> list, int x, int height, Insets insets) {
for (Component component : list) {
if (component.isVisible()) {
Dimension size = component.getPreferredSize();
int y = 0;
if (myAlignment == -1) {
size.height = height;
}
else if (myAlignment != SwingConstants.TOP) {
y = height - size.height;
if (myAlignment == SwingConstants.CENTER) {
y /= 2;
}
}
component.setBounds(x + insets.left, y + insets.top, size.width, size.height);
x += size.width + myGap;
}
}
return x;
}
@Override
protected void installDefaults() {
super.installDefaults();
separatorColor = UIManager.getColor( "TableHeader.separatorColor" );
bottomSeparatorColor = UIManager.getColor( "TableHeader.bottomSeparatorColor" );
height = UIManager.getInt( "TableHeader.height" );
switch( Objects.toString( UIManager.getString( "TableHeader.sortIconPosition" ), "right" ) ) {
default:
case "right": sortIconPosition = SwingConstants.RIGHT; break;
case "left": sortIconPosition = SwingConstants.LEFT; break;
case "top": sortIconPosition = SwingConstants.TOP; break;
case "bottom": sortIconPosition = SwingConstants.BOTTOM; break;
}
}
/**
* Updates the location of <code>this</code> tab overview button.
*
* @param tabbedPane
* Tabbed pane.
* @param tabAreaInsets
* Tab area insets.
*/
public void updateLocation(JTabbedPane tabbedPane, Insets tabAreaInsets) {
if (tabbedPane == null)
return;
// Lock the button for the bounds change
this.putClientProperty(TabOverviewButton.OWN_BOUNDS, Boolean.TRUE);
int buttonSize = SubstanceSizeUtils.getLookupButtonSize();
switch (tabbedPane.getTabPlacement()) {
case SwingConstants.TOP:
if (tabbedPane.getComponentOrientation().isLeftToRight())
this.setBounds(2, tabAreaInsets.top, buttonSize, buttonSize);
else
this.setBounds(tabbedPane.getBounds().width - tabAreaInsets.right - buttonSize - 2,
tabAreaInsets.top, buttonSize, buttonSize);
break;
case SwingConstants.BOTTOM:
if (tabbedPane.getComponentOrientation().isLeftToRight())
this.setBounds(2,
tabbedPane.getBounds().height - tabAreaInsets.bottom - buttonSize - 4,
buttonSize, buttonSize);
else
this.setBounds(tabbedPane.getBounds().width - tabAreaInsets.right - buttonSize - 2,
tabbedPane.getBounds().height - tabAreaInsets.bottom - buttonSize - 4,
buttonSize, buttonSize);
break;
case SwingConstants.LEFT:
this.setBounds(2, tabAreaInsets.top - 1, buttonSize, buttonSize);
break;
case SwingConstants.RIGHT:
this.setBounds(tabbedPane.getBounds().width - tabAreaInsets.right - buttonSize - 2,
tabAreaInsets.top - 1, buttonSize, buttonSize);
break;
}
// Unlock the button for the bounds change
this.putClientProperty(TabOverviewButton.OWN_BOUNDS, null);
}
/**
* Constructor.
*
* @param file MPP file to be displayed in this view.
*/
public MppFilePanel(File file)
{
m_treeModel = new PoiTreeModel();
m_treeController = new PoiTreeController(m_treeModel);
m_treeView = new PoiTreeView(m_treeModel);
m_treeView.setShowsRootHandles(true);
m_hexDumpModel = new HexDumpModel();
m_hexDumpController = new HexDumpController(m_hexDumpModel);
setLayout(new GridLayout(0, 1, 0, 0));
m_hexDumpView = new HexDumpView(m_hexDumpModel);
JSplitPane splitPane = new JSplitPane();
splitPane.setDividerLocation(0.3);
add(splitPane);
JScrollPane scrollPane = new JScrollPane(m_treeView);
splitPane.setLeftComponent(scrollPane);
final JTabbedPane tabbedPane = new JTabbedPane(SwingConstants.TOP);
splitPane.setRightComponent(tabbedPane);
tabbedPane.add("Hex Dump", m_hexDumpView);
m_treeView.addTreeSelectionListener(new TreeSelectionListener()
{
@Override public void valueChanged(TreeSelectionEvent e)
{
TreePath path = e.getPath();
Object component = path.getLastPathComponent();
if (component instanceof DocumentEntry)
{
m_hexDumpController.viewDocument((DocumentEntry) component);
}
}
});
m_treeController.loadFile(file);
}
/**
* Creates a new TriangleIcon.
*
* @param direction
* one of the SwingConstant constants for NORTH, SOUTH, EAST or
* WEST. For example, if the direction is EAST this triangle will
* point to the right.
* @param width
* the width of this icon
* @param height
* the height of this icon
* @param color
* the color to fill this icon with.
*/
public TriangleIcon(int direction, int width, int height, Color color) {
this.direction = direction;
this.width = width;
this.height = height;
this.color = color;
if (direction == SwingConstants.EAST
|| direction == SwingConstants.RIGHT) {
triangle.moveTo(0, 0);
triangle.lineTo(width, height / 2);
triangle.lineTo(0, height);
} else if (direction == SwingConstants.WEST
|| direction == SwingConstants.LEFT) {
triangle.moveTo(width, 0);
triangle.lineTo(0, height / 2);
triangle.lineTo(width, height);
} else if (direction == SwingConstants.NORTH
|| direction == SwingConstants.TOP) {
triangle.moveTo(0, height);
triangle.lineTo(width / 2, 0);
triangle.lineTo(width, height);
} else if (direction == SwingConstants.SOUTH
|| direction == SwingConstants.BOTTOM) {
triangle.moveTo(0, 0);
triangle.lineTo(width / 2, height);
triangle.lineTo(width, 0);
} else {
throw new IllegalArgumentException(
"direction ("
+ direction
+ ") must be one of the SwingConstant constants: NORTH, SOUTH, EAST or WEST.");
}
triangle.closePath();
}
@Override
public void setBounds(final Rectangle BOUNDS) {
if (BOUNDS.width <= BOUNDS.height) {
// vertical
int yNew;
switch(verticalAlignment) {
case SwingConstants.TOP:
yNew = BOUNDS.y;
break;
case SwingConstants.BOTTOM:
yNew = BOUNDS.y + (BOUNDS.height - BOUNDS.width);
break;
case SwingConstants.CENTER:
default:
yNew = BOUNDS.y + ((BOUNDS.height - BOUNDS.width) / 2);
break;
}
super.setBounds(BOUNDS.x, yNew, BOUNDS.width, BOUNDS.width);
} else {
// horizontal
int xNew;
switch(horizontalAlignment) {
case SwingConstants.LEFT:
xNew = BOUNDS.x;
break;
case SwingConstants.RIGHT:
xNew = BOUNDS.x + (BOUNDS.width - BOUNDS.height);
break;
case SwingConstants.CENTER:
default:
xNew = BOUNDS.x + ((BOUNDS.width - BOUNDS.height) / 2);
break;
}
super.setBounds(xNew, BOUNDS.y, BOUNDS.height, BOUNDS.height);
}
calcInnerBounds();
init(getGaugeBounds().width, getGaugeBounds().height);
setInitialized(true);
}
/**
* Creates a layout with the specified gap and vertical alignment.
* All components will have preferred sizes.
*
* @param gap horizontal gap between components
* @param alignment vertical alignment for components
*
* @see SwingConstants#TOP
* @see SwingConstants#BOTTOM
* @see SwingConstants#CENTER
*/
public HorizontalLayout(int gap, int alignment) {
myGap = gap;
switch (alignment) {
case SwingConstants.TOP:
case SwingConstants.BOTTOM:
case SwingConstants.CENTER:
myAlignment = alignment;
break;
default:
throw new IllegalArgumentException("unsupported alignment: " + alignment);
}
}
@Override
public void setBounds(final int X, final int Y, final int WIDTH, final int HEIGHT) {
if (WIDTH <= HEIGHT) {
// vertical
int yNew;
switch(verticalAlignment) {
case SwingConstants.TOP:
yNew = Y;
break;
case SwingConstants.BOTTOM:
yNew = Y + (HEIGHT - WIDTH);
break;
case SwingConstants.CENTER:
default:
yNew = Y + ((HEIGHT - WIDTH) / 2);
break;
}
super.setBounds(X, yNew, WIDTH, WIDTH);
} else {
// horizontal
int xNew;
switch(horizontalAlignment) {
case SwingConstants.LEFT:
xNew = X;
break;
case SwingConstants.RIGHT:
xNew = X + (WIDTH - HEIGHT);
break;
case SwingConstants.CENTER:
default:
xNew = X + ((WIDTH - HEIGHT) / 2);
break;
}
super.setBounds(xNew, Y, HEIGHT, HEIGHT);
}
calcInnerBounds();
init(getGaugeBounds().width, getGaugeBounds().height);
setInitialized(true);
}
@Override
protected void paintContentBorder(Graphics g, int tabPlacement, int selectedIndex) {
// Calculate the content area
int width = tabPane.getWidth();
int height = tabPane.getHeight();
Insets insets = tabPane.getInsets();
int x = insets.left;
int y = insets.top;
// Adjust for tabs. Only top and bottom positions are supported for now.
int tabHeight = calculateTabAreaHeight(tabPlacement, runCount, maxTabHeight);
switch (tabPlacement) {
case SwingConstants.TOP:
y += tabHeight;
break;
default:
// keep at top
}
height -= tabHeight;
// Drawing the background is this method's responsibility, even though
// Thats not obvious from the name
StyleUtil.fillBackground(style, g, x, y, width, height);
// Then the actual border
style.getBorder().paintBorder(tabPane, g, x, y, width, height);
// Paint background over the area between the selected tab and the
// content area
int selected = tabPane.getSelectedIndex();
Rectangle r = getTabBounds(selected, calcRect);
r = r.intersection(new Rectangle(x, y, width, height));
// Find out the border width
int bwidth = style.getBorder().getBorderInsets(tabPane).left;
StyleUtil.fillBackground(style, g, r.x + bwidth, r.y,
r.width - 2 * bwidth, r.height);
}
@Override
public void setBounds(final int X, final int Y, final int WIDTH, final int HEIGHT) {
if (WIDTH <= HEIGHT) {
// vertical
int yNew;
switch(verticalAlignment) {
case SwingConstants.TOP:
yNew = Y;
break;
case SwingConstants.BOTTOM:
yNew = Y + (HEIGHT - WIDTH);
break;
case SwingConstants.CENTER:
default:
yNew = Y + ((HEIGHT - WIDTH) / 2);
break;
}
super.setBounds(X, yNew, WIDTH, WIDTH);
} else {
// horizontal
int xNew;
switch(horizontalAlignment) {
case SwingConstants.LEFT:
xNew = X;
break;
case SwingConstants.RIGHT:
xNew = X + (WIDTH - HEIGHT);
break;
case SwingConstants.CENTER:
default:
xNew = X + ((WIDTH - HEIGHT) / 2);
break;
}
super.setBounds(xNew, Y, HEIGHT, HEIGHT);
}
calcInnerBounds();
init(getGaugeBounds().width, getGaugeBounds().height);
setInitialized(true);
}
@Override
public void setBounds(final Rectangle BOUNDS) {
if (BOUNDS.width <= BOUNDS.height) {
// vertical
int yNew;
switch(verticalAlignment) {
case SwingConstants.TOP:
yNew = BOUNDS.y;
break;
case SwingConstants.BOTTOM:
yNew = BOUNDS.y + (BOUNDS.height - BOUNDS.width);
break;
case SwingConstants.CENTER:
default:
yNew = BOUNDS.y + ((BOUNDS.height - BOUNDS.width) / 2);
break;
}
super.setBounds(BOUNDS.x, yNew, BOUNDS.width, BOUNDS.width);
} else {
// horizontal
int xNew;
switch(horizontalAlignment) {
case SwingConstants.LEFT:
xNew = BOUNDS.x;
break;
case SwingConstants.RIGHT:
xNew = BOUNDS.x + (BOUNDS.width - BOUNDS.height);
break;
case SwingConstants.CENTER:
default:
xNew = BOUNDS.x + ((BOUNDS.width - BOUNDS.height) / 2);
break;
}
super.setBounds(xNew, BOUNDS.y, BOUNDS.height, BOUNDS.height);
}
calcInnerBounds();
init(INNER_BOUNDS.width);
initialized = true;
}
@SuppressWarnings("unchecked")
public ConfigurationPanelGUI() {
setLayout(new BorderLayout(0, 0));
JTabbedPane tabbedPane = new JTabbedPane(SwingConstants.TOP);
add(tabbedPane, BorderLayout.CENTER);
JPanel providerConfigPanel = new JPanel();
tabbedPane.addTab(MTGControler.getInstance().getLangService().getCapitalize("PROVIDERS"), MTGConstants.ICON_TAB_PLUGIN,providerConfigPanel, null);
providerConfigPanel.setLayout(new BorderLayout(0, 0));
subTabbedProviders = new JTabbedPane(SwingConstants.TOP);
providerConfigPanel.add(subTabbedProviders);
bottomPanel = new JPanel();
lblCopyright = new JLabel("");
btnHelp = new JLabel(MTGConstants.ICON_SMALL_HELP);
helpComponent = new HelpCompononent();
helpComponent.setPreferredSize(new Dimension(500, 0));
helpComponent.setVisible(false);
bottomPanel.setLayout(new BorderLayout());
bottomPanel.add(lblCopyright,BorderLayout.WEST);
bottomPanel.add(btnHelp,BorderLayout.EAST);
providerConfigPanel.add(bottomPanel, BorderLayout.SOUTH);
providerConfigPanel.add(helpComponent,BorderLayout.EAST);
btnHelp.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
helpComponent.setVisible(!helpComponent.isVisible());
}
});
createTab(MTGControler.getInstance().getLangService().getCapitalize("CARDS"), MTGConstants.ICON_TAB_CARD, PluginRegistry.inst().getEntry(MTGCardsProvider.class));
createTab(MTGControler.getInstance().getLangService().getCapitalize("PICTURES"), MTGConstants.ICON_TAB_PICTURE, PluginRegistry.inst().getEntry(MTGPictureProvider.class));
createTab(MTGControler.getInstance().getLangService().getCapitalize("PRICERS"), MTGConstants.ICON_TAB_PRICES, PluginRegistry.inst().getEntry(MTGPricesProvider.class));
createTab(MTGControler.getInstance().getLangService().getCapitalize("DATABASES"), MTGConstants.ICON_TAB_DAO, PluginRegistry.inst().getEntry(MTGDao.class));
createTab(MTGControler.getInstance().getLangService().getCapitalize("SHOPPERS"), MTGConstants.ICON_TAB_SHOP, PluginRegistry.inst().getEntry(MTGShopper.class));
createTab(MTGControler.getInstance().getLangService().getCapitalize("CARDS_IMPORT_EXPORT"), MTGConstants.ICON_TAB_IMPORT_EXPORT, PluginRegistry.inst().getEntry(MTGCardsExport.class));
createTab(MTGControler.getInstance().getLangService().getCapitalize("DECKS_IMPORTER"), MTGConstants.ICON_TAB_DECK, PluginRegistry.inst().getEntry(MTGDeckSniffer.class));
createTab(MTGControler.getInstance().getLangService().getCapitalize("DASHBOARD_MODULE"), MTGConstants.ICON_TAB_VARIATIONS,PluginRegistry.inst().getEntry(MTGDashBoard.class));
createTab(MTGControler.getInstance().getLangService().getCapitalize("SERVERS"), MTGConstants.ICON_TAB_SERVER, PluginRegistry.inst().getEntry(MTGServer.class));
createTab(MTGControler.getInstance().getLangService().getCapitalize("NOTIFICATION"), MTGConstants.ICON_TAB_NOTIFICATION, PluginRegistry.inst().getEntry(MTGNotifier.class));
createTab(MTGControler.getInstance().getLangService().getCapitalize("CACHES"), MTGConstants.ICON_TAB_CACHE,PluginRegistry.inst().getEntry(MTGPicturesCache.class));
createTab(MTGControler.getInstance().getLangService().getCapitalize("RSS_MODULE"), MTGConstants.ICON_TAB_NEWS, PluginRegistry.inst().getEntry(MTGNewsProvider.class));
createTab(MTGControler.getInstance().getLangService().getCapitalize("WALLPAPER"), MTGConstants.ICON_TAB_WALLPAPER,PluginRegistry.inst().getEntry(MTGWallpaperProvider.class));
createTab(MTGControler.getInstance().getLangService().getCapitalize("BUILDER_MODULE"), MTGConstants.ICON_TAB_CONSTRUCT, PluginRegistry.inst().getEntry(MTGPictureEditor.class));
createTab(MTGControler.getInstance().getLangService().getCapitalize("INDEXER"), MTGConstants.ICON_TAB_SIMILARITY, PluginRegistry.inst().getEntry(MTGCardsIndexer.class));
createTab(MTGControler.getInstance().getLangService().getCapitalize("SUGGESTION"), MTGConstants.ICON_TAB_SUGGESTION, PluginRegistry.inst().getEntry(MTGTextGenerator.class));
createTab(MTGControler.getInstance().getLangService().getCapitalize("SCRIPT"), MTGConstants.ICON_TAB_RULES, PluginRegistry.inst().getEntry(MTGScript.class));
createTab(MTGControler.getInstance().getLangService().getCapitalize("POOL"), MTGConstants.ICON_TAB_POOL, PluginRegistry.inst().getEntry(MTGPool.class));
createTab(MTGControler.getInstance().getLangService().getCapitalize("COMBO"), MTGConstants.ICON_TAB_COMBO, PluginRegistry.inst().getEntry(MTGComboProvider.class));
createTab(MTGControler.getInstance().getLangService().getCapitalize("GED"), MTGConstants.ICON_TAB_GED, PluginRegistry.inst().getEntry(MTGGedStorage.class));
createTab(MTGControler.getInstance().getLangService().getCapitalize("GRADING"), MTGConstants.ICON_TAB_GRADING, PluginRegistry.inst().getEntry(MTGGraders.class));
createTab(MTGControler.getInstance().getLangService().getCapitalize("RECOGNITION"), MTGConstants.ICON_TAB_RECOGNITION, PluginRegistry.inst().getEntry(MTGCardRecognition.class));
tabbedPane.addTab(MTGControler.getInstance().getLangService().getCapitalize("CONFIGURATION"), MTGConstants.ICON_TAB_ADMIN,new ConfigurationPanel(), null);
tabbedPane.addTab(MTGControler.getInstance().getLangService().getCapitalize("ACTIVE_SERVERS"), MTGConstants.ICON_TAB_ACTIVESERVER, new ServersGUI(),null);
tabbedPane.addTab(MTGControler.getInstance().getLangService().getCapitalize("LOGS"), MTGConstants.ICON_TAB_RULES, new LoggerViewPanel(),null);
}
public ImagePanel(Image image) {
this(image, SwingConstants.TOP);
}
/** @return The vertical alignment. */
@SuppressWarnings("static-method")
public int getVAlignment() {
return SwingConstants.TOP;
}
public ImagePanel(Image image) {
this(image, SwingConstants.TOP);
}
/**
* Constructor.
*
* @param file MPP file to be displayed in this view.
*/
public ProjectFilePanel(File file)
{
m_treeModel = new ProjectTreeModel();
m_treeController = new ProjectTreeController(m_treeModel);
setLayout(new GridLayout(0, 1, 0, 0));
m_treeView = new ProjectTreeView(m_treeModel);
m_treeView.setShowsRootHandles(true);
JSplitPane splitPane = new JSplitPane();
splitPane.setDividerLocation(0.3);
add(splitPane);
JScrollPane scrollPane = new JScrollPane(m_treeView);
splitPane.setLeftComponent(scrollPane);
final JTabbedPane tabbedPane = new JTabbedPane(SwingConstants.TOP);
splitPane.setRightComponent(tabbedPane);
m_openTabs = new HashMap<>();
m_treeView.addTreeSelectionListener(new TreeSelectionListener()
{
@Override public void valueChanged(TreeSelectionEvent e)
{
TreePath path = e.getPath();
MpxjTreeNode component = (MpxjTreeNode) path.getLastPathComponent();
if (!(component.getUserObject() instanceof String))
{
ObjectPropertiesPanel panel = m_openTabs.get(component);
if (panel == null)
{
panel = new ObjectPropertiesPanel(component.getUserObject(), component.getExcludedMethods());
tabbedPane.add(component.toString(), panel);
m_openTabs.put(component, panel);
}
tabbedPane.setSelectedComponent(panel);
}
}
});
m_treeController.loadFile(file);
}
public ExtendedJTabbedPane() {
super(SwingConstants.TOP, JTabbedPane.SCROLL_TAB_LAYOUT);
}
static boolean validVerticalKey(int key) {
return ((key == SwingConstants.TOP) || (key == SwingConstants.CENTER) || (key == SwingConstants.BOTTOM));
}